Też proponuję hasła jednostronne, bo nie ma potrzeby ukrywania ich. Rozszyfrowanie ich jest zwykle logicznie niemożliwe. Ostatnio zrobiłem algorytm szyfrowania jednostronnego oparty na xorowaniu. Co prawda wynik jest o połowę krótszy, niż oryginał, ale podczas xorowania przez odwrotność łańcucha, od połowy wyniku się zaczyna lustrzane odbicie, więc nie ma sensu go przechowywać w całości. A na pytanie, czemu trzeba łańcuch odwrócić - to, mam nadzieję, nie muszę odpowiadać....
Oto potrzebne funkcje:
Dwie do konwersji ASCII na indeksy 0-63 (0-9, A-Z, a-z), ostatnia - szyfrowanie właściwe.
function ASCIIToAlphanum(const Value: string): string;
var
I: Integer;
begin
SetLength(Result,Length(Value));
for I:=1 to Length(Value) do
case Value[I] of
'0'..'9':Result[i]:=Char(Byte(Value[I])-48);
'A'..'Z':Result[i]:=Char(Byte(Value[I])-55);
'a'..'z':Result[i]:=Char(Byte(Value[I])-61);
else Result[i]:=Value[I];
end;
end;
function AlphanumToASCII(const Value: string): string;
var
I: Integer;
begin
SetLength(Result,Length(Value));
for I:=1 to Length(Value) do
case Byte(Value[I]) of
0..9: Result[i]:=Char(Byte(Value[I])+48);
10..35:Result[i]:=Char(Byte(Value[I])+55);
36..63:Result[i]:=Char(Byte(Value[I])+61);
else Result[i]:=Value[I];
end;
end;
function PassXor(const Value: string): string;
var
Temp: string;
I: Integer;
begin
Temp:=Value;
if (Length(Temp) mod 2)<>0 then Temp:=Temp+#0;
SetLength(Result,Length(Temp));
for I:=1 to Length(Temp) do
begin
Result[I]:=Char(Byte(Temp[I]) xor Byte(Temp[Length(Temp)-I+1]));
end;
Temp:=Result;
SetLength(Result,Length(Temp) div 2);
Result:=Copy(Temp,1,Length(Temp) div 2);
end;
Użycie:
ShowMessage(AlphanumToASCII(PassXor(ASCIIToAlphanum('Te2kSt7zasZ35yFroW1anEgo62HasLa6'))))
Ta przeplatanka liter różnej wielkości i cyfr daje wynik "RCNOuc5xMSjoXzl7" - za Chiny Ludowe nie wyciągniesz z tego oryginału.