Пример шифрования текста
const
csCryptFirst = 20;
csCryptSecond = 230;
csCryptHeader = 'Crypted';
type
ECryptError = class(Exception);
function CryptString(Str:String):String;
var i,clen : Integer;
begin
clen := Length(csCryptHeader);
SetLength(Result, Length(Str)+clen);
Move(csCryptHeader[1], Result[1], clen);
For i := 1 to Length(Str) do
begin
if i mod 2 = 0 then
Result[i+clen] := Chr(Ord(Str[i]) xor csCryptFirst)
else
Result[i+clen] := Chr(Ord(Str[i]) xor csCryptSecond);
end;
end;
function UnCryptString(Str:String):String;
var i, clen : Integer;
begin
clen := Length(csCryptHeader);
SetLength(Result, Length(Str)-clen);
if Copy(Str, 1, clen) < > csCryptHeader then
raise ECryptError.Create('UnCryptString failed');
For i := 1 to Length(Str)-clen do
begin
if (i) mod 2 = 0 then
Result[i] := Chr(Ord(Str[i+clen]) xor csCryptFirst)
else
Result[i] := Chr(Ord(Str[i+clen]) xor csCryptSecond);
end;
end;
|
|