const c1=52845; c2=22719; ...... procedure TForm1.Button1Click(Sender: TObject);//加密 var i:integer; sSTR,sResult:string[100]; sPWS:word; begin sSTR:=edit2.Text; sPWS:=strtoint(edit1.Text); sResult[0]:=sSTR[0]; for i:=1 to length(sSTR) do begin sResult[i]:=char(byte(sSTR[i]) xor (sPWS shr 8)); sPWS:=(byte(sResult[i])+sPWS)*c1+c2; end; edit2.Text:=sResult; end; procedure TForm1.Button2Click(Sender: TObject);//解密 var i:integer; sSTR,sResult:string[100]; sPWS:word; begin sSTR:=edit2.Text; sPWS:=strtoint(edit1.Text); sResult[0]:=sSTR[0]; for i:=1 to length(sSTR) do begin sResult[i]:=char(byte(sSTR[i]) xor (sPWS shr 8)); sPWS:=(byte(sSTR[i])+sPWS)*c1+c2; end; edit2.Text:=sResult; end;
function TFrm_password.passtofile(pstr:string):string; var a,b:char; str,str1:string; i,j:integer; begin str:=pstr; str1:=''; j:=Length(str); for i:=1 to j do begin a:=str[i]; b:=chr(ord(a)+5); str1:=str1+b; b:=chr(ord(b)+8); str1:=str1+b; b:=chr(ord(b)+13); str1:=str1+b; b:=chr(ord(b)+24); str1:=str1+b; end; passtofile:=str1; end;
直接加密和解密算法{*******************************************************} { } { Decrypt } { } { bitwise compare of each characters XOR 27 } { } { Return string which after bitwise compare } { } {*******************************************************} function Decrypt(s: string; Key: Integer = 27): string; var i: Integer; begin Result := s; for i := 1 to Length(s) do Result[i] := Chr(Ord(s[i]) xor Key); end;{*******************************************************} { } { Encrypt } { } { Call again Decrypt to back to origin } { } { Return string which after bitwise compare } { } {*******************************************************} function Encrypt(s: string; Key : Integer =27): string; begin Result := Decrypt(s, Key); end;
c1=52845;
c2=22719;
......
procedure TForm1.Button1Click(Sender: TObject);//加密
var
i:integer;
sSTR,sResult:string[100];
sPWS:word;
begin
sSTR:=edit2.Text;
sPWS:=strtoint(edit1.Text);
sResult[0]:=sSTR[0];
for i:=1 to length(sSTR) do
begin
sResult[i]:=char(byte(sSTR[i]) xor (sPWS shr 8));
sPWS:=(byte(sResult[i])+sPWS)*c1+c2;
end;
edit2.Text:=sResult;
end;
procedure TForm1.Button2Click(Sender: TObject);//解密
var
i:integer;
sSTR,sResult:string[100];
sPWS:word;
begin
sSTR:=edit2.Text;
sPWS:=strtoint(edit1.Text);
sResult[0]:=sSTR[0];
for i:=1 to length(sSTR) do
begin
sResult[i]:=char(byte(sSTR[i]) xor (sPWS shr 8));
sPWS:=(byte(sSTR[i])+sPWS)*c1+c2;
end;
edit2.Text:=sResult;
end;
var
a,b:char;
str,str1:string;
i,j:integer;
begin
str:=pstr;
str1:='';
j:=Length(str);
for i:=1 to j do
begin
a:=str[i];
b:=chr(ord(a)+5);
str1:=str1+b;
b:=chr(ord(b)+8);
str1:=str1+b;
b:=chr(ord(b)+13);
str1:=str1+b;
b:=chr(ord(b)+24);
str1:=str1+b;
end;
passtofile:=str1;
end;
{ }
{ Decrypt }
{ }
{ bitwise compare of each characters XOR 27 }
{ }
{ Return string which after bitwise compare }
{ }
{*******************************************************}
function Decrypt(s: string; Key: Integer = 27): string;
var
i: Integer;
begin
Result := s;
for i := 1 to Length(s) do
Result[i] := Chr(Ord(s[i]) xor Key);
end;{*******************************************************}
{ }
{ Encrypt }
{ }
{ Call again Decrypt to back to origin }
{ }
{ Return string which after bitwise compare }
{ }
{*******************************************************}
function Encrypt(s: string; Key : Integer =27): string;
begin
Result := Decrypt(s, Key);
end;