Topic: [Script] Simple encrypt and decrypt string
Function:
function StrCrypt(txt, key: string): string;
var
i,z: integer;
begin
result := '';
if Length(txt) > 0 then
begin
z := 1;
for i := 1 to Length(txt) do
begin
txt[i] := Chr(23 XOR Ord(txt[i]));
inc(z);
if z > length(key) then z := 1;
end;
result := txt;
end;
end;
Usage:
Procedure TestCrypt;
var
s : string;
key: string;
begin
s := 'this is a test';
key := '7317da37A13712';
s := StrCrypt(s,key);
ShowMessage('Encrypt: ' + s);
s := StrCrypt(s,key);
ShowMessage('Decrypt: ' + s);
end;