Mega Code Archive
A very simple XOR encrypting routine (for beginners)
Title: A very simple XOR encrypting routine (for beginners)
Question: With RandSeed variable, you can use Random to create a cryptography routine with unique 32-Bit key to decrypt...
Answer:
A simple unit to easily use criptography...
(*********************************************************************
How to use:
var
s: string;
begin
s := 'Carlos Alberto Longen';
s := Crypt(s,12345);
ShowMessage(Format('Ciphered: %s', [s]));
ShowMessage(Format('Deciphered: %s', [decrypt(s,12345)]));
*********************************************************************)
unit untCrypt;
interface
// ciphers the string "strText" with 32-bit "code" "intCode"
function Crypt(const strText: string; const intKey: longint): string;
// deciphers the string "strText" with 32-bit "code" "intCode"
function Decrypt(const strText: string; const intKey: longint): string;
const
// "default key" - select a "standard" for you...
intDefKey = -967283;
implementation
// ciphers the string "strText" with 32-bit "code" "intCode"
function Crypt(const strText: string; const intKey: longint): string;
var
i: integer;
strResult: string;
begin
// initialize result
strResult := strText;
// sync RandSeed key to generate Random chars
RandSeed := intKey;
// cipher
for i := 1 to Length(strText) do
strResult[i] := Chr(Ord(strResult[i]) xor Random(255));
// set results
Crypt := strResult;
end;
// deciphers the string "strText" with 32-bit "code" "intCode"
function Decrypt(const strText: string; const intKey: longint): string;
begin
// deciphers the string
Decrypt := Crypt(strText, intKey);
end;
end.