Supongo que existen cifrados parecidos a lo que yo hago en este, pero bueno, ahí va el mío.
El nombre es así porque se basa en una "clave" estática que lleva su nombre, que es la que finalmente determinará el resultado final.
Os cuento un poco cómo funciona:
Si tenemos por ejemplo un caracter cuyo valor decimal es "000" ($00), en primer lugar sumaremos el valor de sKey, por ejemplo 2; 000 + 2 = 002
Finalmente cada numero es reemplazado por el número de letra de la key estática que le corresponda: 0 = L, 2 = C
Obteniendo de resultado "LLC" al cifrar "002".
Para descifrar se hace la operación contraria (nomedigas.jpg).
El code:
Cifrar:
function L213Cif(Texto: string; sKey: integer): string;
var
R: string;
R1: string;
sByte: byte;
i, o: integer;
const
LF: array [0 .. 9] of char = ('L','U','C','I','F','E','R','2','1','3');
begin
if sKey > 744 then
raise Exception.Create('El valor de la Clave debe ser menor o igual a 744.');
Result := '';
R1:= '';
for I := 1 to Length(Texto) do
begin
sByte:= ord(Texto[i]);
R := inttostr(sByte + sKey);
while Length(R) <> 3 do
insert('0', R, 1);
for o := 1 to 3 do
R1 := R1 + LF[strtoint(R[o])]; // Si sKey = 0 --> 012 = LUC
end;
SetLength(Result, Length(R1));
Result:= R1;
end;
Descifrar:function L213Dec(Cif: string; sKey: integer): string;
var
i: integer;
R: string;
R1: string;
Aux: string;
const
LF: array [0 .. 9] of char = ('L','U','C','I','F','E','R','2','1','3');
begin
if sKey > 744 then
raise Exception.Create('El valor de la Clave debe ser menor o igual a 744.');
R1:= '';
R:= '';
Result:= '';
for I := 1 to length(Cif) do
R:= R + inttostr(pos(Cif[i], LF)-1);
repeat
Aux:= copy(R, 1, 3);
R1:= R1 + chr(strtoint(Aux)-sKey);
Delete(R, 1, 3);
until R = '';
SetLength(Result, Length(R1));
Result:= R1;
end;
Ejemplo:var
e, d: string;
begin
e:= L213cif('Hola puta.', 20); //L3CUIUUC1UU2LECUICUI2UIRUU2LRR
d:= L213dec(e, 20); //Hola puta.
showmessage(e + #13#10 + d);
end;
Saludos.