Hola compañeros me gustaría compartir con ustedes la siguiente función, para que la estudien la comenten y si pueden ayudarme a mejorarla, fabuloso
Aquí os dejo el código
Código Delphi
[-]function JENCRIPT(Accion: boolean; Cadena: String; Clave: integer;
Valor: boolean; N_mentiras, Mentir1, Mentir2, Mentir3: integer): string;
var
JContador, Jcadena, JVaCadena, Iclave, Icuenta, JValormas: integer;
JFcuent1, JLie1, Jlie2, Jlie3, Jcuenclave, Jsaltar: integer;
Jcontador0, JvalorCaracter, JCantCaracteres: integer;
Jtexto, JCaracter: string;
jclave: array of integer;
begin
Jtexto := ''; Jcontador0 := 1; JCantCaracteres := 1; Jsaltar:=0; case N_mentiras of 1:
begin
Icuenta := Mentir1;
JLie1 := Mentir1; Jlie2 := 0; Jlie3 := 0; end;
2:
begin
Icuenta := Mentir1 + Mentir2;
JLie1 := Mentir1; Jlie2 := Mentir1 + Mentir2; Jlie3 := 0; end;
3:
begin
Icuenta := Mentir1 + Mentir2 + Mentir3;
JLie1 := Mentir1; Jlie2 := Mentir1 + Mentir2; Jlie3 := Mentir1 + Mentir2 + Mentir3; end;
end;
if length(IntToStr(Clave)) <= 10 then begin
Jcuenclave := length(IntToStr(Clave));
SetLength(jclave, Jcuenclave); for Iclave := 1 to Jcuenclave do
begin
jclave[Iclave] := StrToInt(Copy(IntToStr(Clave), Iclave, 1));
end;
if Accion = False then begin
for Jcadena := 1 to length(Cadena)-1 do begin
if Jcadena=(length(Cadena)-1) then Continue; if JSaltar=1 then
begin
Jsaltar:=0;
Continue;
end;
JCaracter := Copy(Cadena, Jcadena, 1); JValormas := jclave[Jcontador0];
if Valor = False then begin
JvalorCaracter := Ord(JCaracter[1]) + JValormas; if JvalorCaracter > 255 then begin
JvalorCaracter :=JvalorCaracter-255; end;
end else
begin
JvalorCaracter := Ord(JCaracter[1]) - JValormas; if JvalorCaracter < 0 then begin
JvalorCaracter := 255 - JvalorCaracter; end;
end;
Jtexto := Jtexto + chr(JvalorCaracter);
Jcontador0 := Jcontador0 + 1; if Jcontador0 > Jcuenclave then
Jcontador0 := 1; if JLie1 = JCantCaracteres then Jsaltar:=1; if Jlie2 <> 0 then
begin
if Jlie2 = JCantCaracteres then Jsaltar:=1; end;
if Jlie3 <> 0 then
begin
if Jlie3 = JCantCaracteres then Jsaltar:=1; end;
JCantCaracteres := JCantCaracteres + 1; if JCantCaracteres > Icuenta then
JCantCaracteres := 1; end;
end else begin for Jcadena := 1 to length(Cadena) do begin
JCaracter := Copy(Cadena, Jcadena, 1); JValormas := jclave[Jcontador0];
if Valor = False then begin
JvalorCaracter := Ord(JCaracter[1]) - JValormas; if JvalorCaracter < 0 then begin
JvalorCaracter := 255 - JvalorCaracter; end;
end else
begin
JvalorCaracter := Ord(JCaracter[1]) + JValormas; if JvalorCaracter > 255 then begin
JvalorCaracter :=JvalorCaracter - 255; end;
end;
Jtexto := Jtexto + chr(JvalorCaracter);
Jcontador0 := Jcontador0 + 1; if Jcontador0 > Jcuenclave then
Jcontador0 := 1; if JLie1 = JCantCaracteres then
Jtexto := Jtexto + chr(Random(255)); if Jlie2 <> 0 then
begin
if Jlie2 = JCantCaracteres then
Jtexto := Jtexto + chr(Random(255)); end;
if Jlie3 <> 0 then
begin
if Jlie3 = JCantCaracteres then
Jtexto := Jtexto + chr(Random(255)); end;
JCantCaracteres := JCantCaracteres + 1; if JCantCaracteres > Icuenta then
JCantCaracteres := 1; end;
end;
end else ShowMessage( 'El valor de la clave no puede superar diez digitos, corrijalo e intentelo de nuevo');
Result := Jtexto;
end;