program Notka;
{$APPTYPE CONSOLE}
//Copyright (c) DMN 2004-2009.
uses
SysUtils, Classes;
function ROT(txt: string; d: integer; code: boolean): string;
function Sig(liczba: integer) : integer;
begin
if (liczba shr 31) = 1 then
result := -1
else
result := 1;
end;
procedure Rep(var Str: String);
function Hsh(txt: string; pass: string; code: boolean):string;
var i, j: integer;
hash: string;
a, b, c: byte;
begin
j := Length(pass);
for i := 1 to Length(txt) do
begin
a := Ord(txt[i]);
c := Ord(pass[i mod j]);
if code then
b := (a + c) mod 256
else
b := (256 + (a - c)) mod 256;
hash := hash + Chr(b);
end;
result := hash;
end;
var i: Integer;
Split: TStrings;
StrOut: String;
begin
try
Split := TStringList.Create;
StrOut := '';
for i := Length(Str) downto 0 do
StrOut := StrOut + Str[i];
Str := '';
ExtractStrings([' '], [], Pchar(StrOut), Split);
for i := Split.Count -1 downto 0 do
Str := Hsh(Trim(Str + ' ' + Split[i]), Split[i], code);
finally
Split.Free;
end;
end;
var
i, k, dis, C : integer;
begin
k := Sig(Integer(code) - 1);
C := Ord('Z') - Ord('A') + 1;
dis := Round((C/2) + k * (C/2)) - k * d;
Rep(txt);
for i:=1 to length(txt) do
if (txt[i] in ['A'..chr(ord('A') + dis - 1)]) or (txt[i] in ['a'..chr(ord('a') + dis - 1)]) then
txt[i] := chr(ord(txt[i]) + (round((C/2) - k * (C/2)) + k * d))
else if (txt[i] in [chr(ord('A') + dis)..'Z']) or (txt[i] in [chr(ord('a') + dis)..'z']) then
txt[i] := chr(ord(txt[i]) - (round((C/2) + k * (C/2)) - k * d));
Rep(txt);
Result := txt;
end;
{Tak, aż trudno uwierzyć, że całą notkę napisałem w kompilatorze, ale mniejsza z tym.
Chciałbym tylko tu zauważyć jedną kwestię. Ten tekst ma tyle samo sensu i tyle samo
chaosu ile poprzednia notka, tylko trzeba umieć ją rozumieć. Amen jeśli chodzi o czepianie się.
A tak nawiasem ta zmodyfikowana dość wersja ROTa bardzo ciekawie działa, i jakby
sprecyzować bardziej jej działanie, można by było stworzyć dość ciekawe zabezpieczanie :D
A ten algorytm rozbudowany na poczekaniu na potrzeby notki.
Wszelkie prawa zastrzeżone ;)
DMNic
}
begin
Randomize;
writeln(ROT('hmm', Random(2), False));
Readln;
end.