function Encrypt(mStr: string; mKey: string): string;
var
I, J: Integer;
begin
J := 1;
Result := '';
for I := 1 to Length(mStr) do begin
Result := Result + Char(Ord(mStr[I]) xor Ord(mKey[J]));
if J + 1 <= Length(mKey) then
Inc(J)
else J := 1;
end;
{自己加步骤}
end;function Decrypt(mStr: string; mKey: string): string;
var
I, J: Integer;
begin
J := 1;
Result := '';
{自己加步骤}
for I := 1 to Length(mStr) do begin
Result := Result + Char(Ord(mStr[I]) xor Ord(mKey[J]));
if J + 1 <= Length(mKey) then
Inc(J)
else J := 1;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
const
cKey1 = '谁想试试怎么破';
cKey2 = '我可不愿意这样玩(1)我可不愿意这样玩(2)我可不愿意这样玩(3)';
cKey3 = 'Memo2.Text := Decrypt(Encrypt(Memo1.Text, cKey), cKey);';
var
S: string; //加密后的字符
begin
S := Encrypt(Encrypt(Encrypt(Memo1.Text, cKey1), cKey2), cKey3);
ShowMessage(S);
Memo2.Text := Decrypt(Decrypt(Decrypt(S, cKey3), cKey2), cKey1);
end;
var
I, J: Integer;
begin
J := 1;
Result := '';
for I := 1 to Length(mStr) do begin
Result := Result + Char(Ord(mStr[I]) xor Ord(mKey[J]));
if J + 1 <= Length(mKey) then
Inc(J)
else J := 1;
end;
{自己加步骤}
end;function Decrypt(mStr: string; mKey: string): string;
var
I, J: Integer;
begin
J := 1;
Result := '';
{自己加步骤}
for I := 1 to Length(mStr) do begin
Result := Result + Char(Ord(mStr[I]) xor Ord(mKey[J]));
if J + 1 <= Length(mKey) then
Inc(J)
else J := 1;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
const
cKey1 = '谁想试试怎么破';
cKey2 = '我可不愿意这样玩(1)我可不愿意这样玩(2)我可不愿意这样玩(3)';
cKey3 = 'Memo2.Text := Decrypt(Encrypt(Memo1.Text, cKey), cKey);';
var
S: string; //加密后的字符
begin
S := Encrypt(Encrypt(Encrypt(Memo1.Text, cKey1), cKey2), cKey3);
ShowMessage(S);
Memo2.Text := Decrypt(Decrypt(Decrypt(S, cKey3), cKey2), cKey1);
end;
function StringToFile(mString: string; mFileName: TFileName): Boolean;
var
vFile: file of Char;
I: Integer;
begin
{$I-}
AssignFile(vFile, mFileName);
Rewrite(vFile);
for I := 1 to Length(mString) do Write(vFile, mString[I]);
CloseFile(vFile);
{$I+}
Result := (IOResult = 0) and (mFileName <> '');
end; { StringToFile }function FileToString(mFileName: TFileName): string;
var
vFile: file of Char;
vChar: Char;
begin
Result := '';
{$I-}
AssignFile(vFile, mFileName);
Reset(vFile);
while not Eof(vFile) do begin
Read(vFile, vChar);
Result := Result + vChar;
end;
CloseFile(vFile);
{$I+}
end; { FileToString }