program XORCipher;
function XORCipher(const Input, Key: string): string;
var
i, keyIndex: Integer;
begin
SetLength(XORCipher, Length(Input));
for i := 1 to Length(Input) do
begin
keyIndex := ((i - 1) mod Length(Key)) + 1;
XORCipher[i] := Chr(Ord(Input[i]) xor Ord(Key[keyIndex]));
end;
end;
var
Str, Key, EncryptedText, DecryptedText: string;
begin
// Input data
Str := 'May the Force be with you.';
Key := 'Obelus'; // String key for XOR operation
// Encrypt the string
EncryptedText := XORCipher(Str, Key);
Writeln('Encrypted Text: ', EncryptedText);
// Decrypt the string (same function, same key)
DecryptedText := XORCipher(EncryptedText, Key);
Writeln('Decrypted Text: ', DecryptedText);
end.
(*
run:
Encrypted Text: L*B#*B U&L:L
Decrypted Text: May the Force be with you.
*)