文
文生
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls;type TForm1 = class(TForm) LabeledEdit1: TLabeledEdit; LabeledEdit2: TLabeledEdit; BitBtn1: TBitBtn; BitBtn2: TBitBtn; Memo1: TMemo; Memo2: TMemo; Edit1: TEdit; procedure BitBtn1Click(Sender: TObject); procedure BitBtn2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}//将一个十进制整型转换成二进制值 参数说明:Int:被转换的整型值//Size:转换后的宽度:4位 8位 或更大Function Str_IntToBin(Int: LongInt; Size: Integer): String;Var i: Integer;Begin If Size < 1 Then Exit; For i := Size Downto 1 Do Begin If Int And (1 Shl (Size - i)) <> 0 Then Result := '1' + Result Else Result := '0' + Result; End;End;//二进制 to 十进制function BintoInt(Value: String): LongInt;var i,Size: Integer;begin Result:=0; Size:=Length(Value); for i:=Size downto 1 do begin if Copy(Value,i,1)='1' then Result:=Result+(1 shl (Size-i)); end;end;procedure TForm1.BitBtn1Click(Sender: TObject);var s,s1,s2,st:String; i,xmod:integer;begin s := Trim(LabeledEdit1.Text) ; if length(s)<=0 then Exit ; s2 := '' ; memo1.Clear ; for i:=1 to Length(s) do begin xmod := i mod 8 ; st := '' ; s1 := '' ; st := Str_IntToBin(Ord(s), 8) ; if xmod>0 then s1 := Copy(st, 8-xmod+1, xMod) + Copy(st, 1, 8-xmod) else s1 := st ; memo1.Lines.Add(format('%s %D %S %S %S', [s, xmod, st, s1, IntToHex(BintoInt(s1), 2)])) ; s2 := s2 + IntToHex(BintoInt(s1), 2) ; end; LabeledEdit2.Text := s2 ;end;procedure TForm1.BitBtn2Click(Sender: TObject);begin///////// 解密end;end.