unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Button1: TButton; Edit3: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function Encrypt(s: string): string; var tmpstr:string; i:integer; begin tmpstr := ''; for i:=1 to length(s) do begin tmpstr:=tmpstr + IntToHex(not ord(s[i]) xor $0AA,2); end; result := tmpstr; end; function myStrtoHex(s: string): string; var tmpstr:string; i:integer; begin tmpstr := ''; for i:=1 to length(s) do begin tmpstr := tmpstr + inttoHex(ord(s[i]),2); end; result :=tmpstr; end; function myHextoStr(S: string): string; var hexS,tmpstr:string; i:integer; a:byte; begin hexS :=s; if length(hexS) mod 2=1 then begin hexS:=hexS+'0'; end; tmpstr:=''; for i:=1 to (length(hexS) div 2) do begin a:=strtoint('$'+hexS[2*i-1]+hexS[2*i]); tmpstr := tmpstr+chr(a); end; result :=tmpstr; end; function HextoBack(S: string): string; var hexS,tmpstr:string; i:integer; a:byte; begin hexS :=s; if length(hexS) mod 2=1 then begin hexS:=hexS+'0'; end; tmpstr:=''; for i:=1 to (length(hexS) div 2) do begin a:=strtoint('$'+hexS[2*i-1]+hexS[2*i]); tmpstr := chr(a)+tmpstr; end; result :=tmpstr; end; procedure TForm1.Button1Click(Sender: TObject); var tmpstr:string; i:integer; s1,s2,s3,s4:string; begin s1:=Edit1.Text; for i:=1 to length(s1) do begin tmpstr := tmpstr + inttoHex(ord(s1[i])+ord(s1[i-1]),2); end; s2:=tmpstr+inttoHex(ord(s1[length(s1)]),2); s3:=Copy(s2,3,Length(s2)); s4:=myStrtoHex(HextoBack(s3)); Edit2.Text:=Encrypt(myHextoStr(s4)); Edit3.Text:=myHextoStr(Edit2.Text); end; end.