Mega Code Archive

 
Categories / Delphi / Strings
 

Bir stringin sifrelenmesi ve bu sifrenin cözülmesi

uses WinCRT; const KML1 = 52845; KML2 = 22719; function Sifrele(const S: String; Key: Word): String; var I: byte; begin Result[0] := S[0]; for I := 1 to Length(S) do begin Result[I] := char(byte(S[I]) xor (Key shr 8)); Key := (byte(Result[I]) + Key) * KML1 + KML2; end; end; function SifreCoz(const S: String; Key: Word): String; var I: byte; begin Result[0] := S[0]; for I := 1 to Length(S) do begin Result[I] := char(byte(S[I]) xor (Key shr 8)); Key := (byte(S[I]) + Key) * KML1 + KML2; end; end; var S: string; begin Write('>'); ReadLn(S); S := Sifrele(S,12345); WriteLn(S); S := SifreCoz(S,12345); WriteLn(S); end. // Kemal GÜLOL gulolkml@hotmail.com