private
{ Déclarations privées }
function Crypter:boolean;
function Decrypter:boolean;
function AlgoCesar(decalage:integer;texte:string):string;
function VigenereCrypt(password,texte:string):string;
function VigenereDecrypt(password,texte:string):string;
//
function Tform1.AlgoCesar(decalage:integer;texte:string):string;
var tmp:string;
i:integer;
begin
tmp:='';
for i:=1 to length(texte) do
begin
tmp:=tmp+chr(ord(texte[i])+decalage);
end;
AlgoCesar:=tmp;
end;
function Tform1.VigenereCrypt(password,texte:string):string;
var i,nb:integer;
tmp:string;
begin
tmp:='';
nb:=1;
for i:=1 to length(texte) do
begin
tmp:=tmp+chr(ord(texte[i])+ord(password[nb]));
nb:=nb+1;
if nb>length(password) then
begin
nb:=1;
end;
end;
VigenereCrypt:=tmp;
end;
function Tform1.VigenereDecrypt(password,texte:string):string;
var i,nb:integer;
tmp:string;
begin
tmp:='';
nb:=1;
for i:=1 to length(texte) do
begin
tmp:=tmp+chr((ord(texte[i])+256)-ord(password[nb]));
nb:=nb+1;
if nb>length(password) then
begin
nb:=1;
end;
end;
VigenereDecrypt:=tmp;
end;
function Tform1.Crypter:boolean;
begin
memo2.text:=VigenereCrypt(AlgoCesar(SpinEdit2.value,Edit1.text),
AlgoCesar((0-SpinEdit1.value),memo1.text));
if AlgoCesar(SpinEdit1.value,
VigenereDeCrypt(AlgoCesar(SpinEdit2.value,edit1.text),Memo2.text))=Memo1.text then
begin
crypter:=true;
end
else
begin
crypter:=false;
end;
end;
function Tform1.Decrypter:boolean;
begin
Memo1.text := AlgoCesar(SpinEdit1.value,
VigenereDeCrypt(AlgoCesar(SpinEdit2.value,edit1.text),memo2.text));
end;
Crypt :
procedure TForm1.Button1Click(Sender: TObject);
begin
if crypter=true then
begin
//showmessage('Crypt done !');
end
else
begin
//showmessage('Crypt failed !');
end;
end;
Decrypt :
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.text:=AlgoCesar(SpinEdit1.value,
VigenereDeCrypt(AlgoCesar(SpinEdit2.value,edit1.text),Memo2.text));
end;
Keine Kommentare:
Kommentar veröffentlichen