📄 passs.pas
字号:
unit passs;
interface
uses
SysUtils, Classes;
const
c1=52845;
c2=22719;
type
TDataModule1 = class(TDataModule)
private
{ Private declarations }
public
{ Public declarations }
function Decrypt(const S: String; Key: Word): String;
function Encrypt(const S: String; Key: Word): String;
function HexToStr(AStr: string): string;
function StrToHex(AStr: string): string;
function TransChar(AChar: Char): Integer;
end;
var
DataModule1: TDataModule1;
implementation
{$R *.dfm}
function TDataModule1.TransChar(AChar: Char): Integer;
begin
if AChar in ['0'..'9'] then
Result:=Ord(AChar)-Ord('0')
else
Result:=10+Ord(AChar)-Ord('A');
end;
function TDataModule1.StrToHex(AStr: string): string;
var
I:Integer;
Tmp:string;
begin
Result:='';
For I:=1 to Length(AStr) do
begin
Result:=Result+Format('%2x',[Byte(AStr[I])]);
end;
I :=Pos('',Result);
While I <> 0 do
begin
Result[I]:='0';
I:=Pos('', Result);
end;
end;
function TDataModule1.HexToStr(AStr: string): string;
var
I : Integer;
st:string;
CharValue: Word;
begin
Result:='';
For I:=1 to Trunc(Length(Astr)/2) do
begin
Result:= Result+' ';
CharValue:=TransChar(AStr[2*I-1])*16+TransChar(AStr[2*I]);
result[I]:=char(CharValue);
end;
end;
function TDataModule1.Encrypt(const S: String; Key: Word): String;
var
I:Integer;
begin
Result := S;
for I := 1 to Length(S) do
begin
Result[I] := char(byte(S[I]) xor (Key shr 8));
Key := (byte(Result[I]) + Key) * C1 + C2;
if Result[I] = Chr(0) then
Result[I] := S[I];
end;
Result := StrToHex(Result);
end;
function TDataModule1.Decrypt(const S: String; Key: Word): String;
var
I: Integer;
S1: string;
begin
S1 := HexToStr(S);
Result := S1;
for I := 1 to Length(S1) do
begin
if char(byte(S1[I]) xor (Key shr 8)) = Chr(0) then
begin
Result[I] := S1[I];
Key := (byte(Chr(0)) + Key) * C1 + C2; //保证Key的正确性
end
else
begin
Result[I] := char(byte(S1[I]) xor (Key shr 8));
Key := (byte(S1[I]) + Key) * C1 + C2;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -