Курсовая работа: Использование современных симметрических (DES) и асимметрических (RSA) алгоритмов шифрования
klu4:string;
t1,t2:TDateTime;
vremja:integer;
razmer:integer;
begin
klu4:=Edit12.text;
while( Length(klu4)<8 ) do
klu4:=klu4+'0';
Formirovanie_16_podklju4ei(klu4);
t1:=Time;
if Form1.RadioButton10.Checked=true then
begin
Raswifrovanie_ECB('DES_crypted\Z_20_7_ECB.txt','DES_uncrypted\R_20_7_ECB.txt');
razmer:=1024*20;
end;
if Form1.RadioButton9.Checked=true then
begin
Raswifrovanie_ECB('DES_crypted\Z_50_7_ECB.txt','DES_uncrypted\R_50_7_ECB.txt');
razmer:=1024*50;
end;
if Form1.RadioButton8.Checked=true then
begin
Raswifrovanie_ECB('DES_crypted\Z_100_7_ECB.txt','DES_uncrypted\R_100_7_ECB.txt');
razmer:=1024*100;
end;
if Form1.RadioButton7.Checked=true then
begin
Raswifrovanie_ECB('DES_crypted\Z_500_7_ECB.txt','DES_uncrypted\R_500_7_ECB.txt');
razmer:=1024*500;
end;
if Form1.RadioButton6.Checked=true then
begin
Raswifrovanie_ECB('DES_crypted\Z_1_7_ECB.txt','DES_uncrypted\R_1_7_ECB.txt');
razmer:=1024*1024;
end;
t2:=Time;
vremja:=round((t2 - t1)*24*60*60)+1;
Label33.Caption := IntToStr(vremja-1)+ 'сек';
Label34.Caption := FloatToStr(razmer/vremja-1)+'байт/сек';
end;
//CBC zawifrovanie failov klju4om na 5 bait
procedure TForm1.Button7Click(Sender: TObject);
var
klu4:string;
vektor:string;
t1,t2:TDateTime;
vremja:integer;
razmer:integer;
begin
klu4:=Edit10.text;
while( Length(klu4)<8 ) do
klu4:=klu4 + '*';
Formirovanie_16_podklju4ei(klu4);
vektor:=Edit1.text;
while( Length(vektor)<8 ) do
vektor:=vektor+ '0';
t1:=Time;
if Form1.RadioButton10.Checked=true then
begin
Wifrovanie_CBC('20.txt','DES_crypted\Z_20_5_CBС.txt',vektor);
razmer:=1024*20;
end;
if Form1.RadioButton9.Checked=true then
begin
Wifrovanie_CBC('50.txt','DES_crypted\Z_50_5_CBС.txt',vektor);
razmer:=1024*50;
end;
if Form1.RadioButton8.Checked=true then
begin
Wifrovanie_CBC('100.txt','DES_crypted\Z_100_5_CBС.txt',vektor);
razmer:=1024*100;
end;
if Form1.RadioButton7.Checked=true then
begin
Wifrovanie_CBC('500.txt','DES_crypted\Z_500_5_CBС.txt',vektor);
razmer:=1024*500;
end;
if Form1.RadioButton6.Checked=true then
begin
Wifrovanie_CBC('1.txt','DES_crypted\Z_1_5_CBС.txt',vektor);
razmer:=1024*1024;
end;
t2:=Time;
vremja:=round((t2 - t1)*24*60*60)+1;
Label34.Caption := IntToStr(vremja-1)+ 'сек';
Label34.Caption := FloatToStr(razmer/vremja-1)+'байт/сек';
end;
//CBC raswifrovanie failov klju4om na 5 bait
procedure TForm1.Button8Click(Sender: TObject);
var
klu4:string;
vektor:string;
t1,t2:TDateTime;
vremja:integer;
razmer:integer;
begin
klu4:=Edit10.text;
while( Length(klu4)<8 ) do
klu4:=klu4 + '*';
Formirovanie_16_podklju4ei(klu4);
vektor:=Edit1.text;
while( Length(vektor)<8 ) do
vektor:=vektor+ '0';
t1:=Time;
if Form1.RadioButton10.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_20_5_CBС.txt','DES_uncrypted\R_20_5_CBС.txt',vektor);
razmer:=1024*20;
end;
if Form1.RadioButton9.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_50_5_CBС.txt','DES_uncrypted\R_50_5_CBС.txt',vektor);
razmer:=1024*50;
end;
if Form1.RadioButton8.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_100_5_CBС.txt','DES_uncrypted\R_100_5_CBС.txt',vektor);
razmer:=1024*100;
end;
if Form1.RadioButton7.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_500_5_CBС.txt','DES_uncrypted\R_500_5_CBС.txt',vektor);
razmer:=1024*500;
end;
if Form1.RadioButton6.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_1_5_CBС.txt','DES_uncrypted\R_1_5_CBС.txt',vektor);
razmer:=1024*1024;
end;
t2:=Time;
vremja:=round((t2 - t1)*24*60*60)+1;
Label33.Caption := IntToStr(vremja-1)+ 'сек';
Label34.Caption := FloatToStr(razmer/vremja-1)+'байт/сек';
end;
//CBC zawifrovanie failov klju4om na 6 bait
procedure TForm1.Button9Click(Sender: TObject);
var
klu4:string;
vektor:string;
t1,t2:TDateTime;
vremja:integer;
razmer:integer;
begin
klu4:=Edit11.text;
while( Length(klu4)<8 ) do
klu4:=klu4 + '*';
Formirovanie_16_podklju4ei(klu4);
vektor:=Edit1.text;
while( Length(vektor)<8 ) do
vektor:=vektor+ '0';
t1:=Time;
if Form1.RadioButton10.Checked=true then
begin
Wifrovanie_CBC('20.txt','DES_crypted\Z_20_6_CBС.txt',vektor);
razmer:=1024*20;
end;
if Form1.RadioButton9.Checked=true then
begin
Wifrovanie_CBC('50.txt','DES_crypted\Z_50_6_CBС.txt',vektor);
razmer:=1024*50;
end;
if Form1.RadioButton8.Checked=true then
begin
Wifrovanie_CBC('100.txt','DES_crypted\Z_100_6_CBС.txt',vektor);
razmer:=1024*100;
end;
if Form1.RadioButton7.Checked=true then
begin
Wifrovanie_CBC('500.txt','DES_crypted\Z_500_6_CBС.txt',vektor);
razmer:=1024*500;
end;
if Form1.RadioButton6.Checked=true then
begin
Wifrovanie_CBC('1.txt','DES_crypted\Z_1_6_CBС.txt',vektor);
razmer:=1024*1024;
end;
t2:=Time;
vremja:=round((t2 - t1)*24*60*60)+1;
Label33.Caption := IntToStr(vremja-1)+ 'сек';
Label34.Caption := FloatToStr(razmer/vremja-1)+'байт/сек';
end;
//CBC raswifrovanie failov klju4om na 6 bait
procedure TForm1.Button10Click(Sender: TObject);
var
klu4:string;
vektor:string;
t1,t2:TDateTime;
vremja:integer;
razmer:integer;
begin
klu4:=Edit11.text;
while( Length(klu4)<8 ) do
klu4:=klu4 + '*';
Formirovanie_16_podklju4ei(klu4);
vektor:=Edit1.text;
while( Length(vektor)<8 ) do
vektor:=vektor+ '0';
t1:=Time;
if Form1.RadioButton10.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_20_6_CBС.txt','DES_uncrypted\R_20_6_CBС.txt',vektor);
razmer:=1024*20;
end;
if Form1.RadioButton9.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_50_6_CBС.txt','DES_uncrypted\R_50_6_CBС.txt',vektor);
razmer:=1024*50;
end;
if Form1.RadioButton8.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_100_6_CBС.txt','DES_uncrypted\R_100_6_CBС.txt',vektor);
razmer:=1024*100;
end;
if Form1.RadioButton7.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_500_6_CBС.txt','DES_uncrypted\R_500_6_CBС.txt',vektor);
razmer:=1024*500;
end;
if Form1.RadioButton6.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_1_6_CBС.txt','DES_uncrypted\R_1_6_CBС.txt',vektor);
razmer:=1024*1024;
end;
t2:=Time;
vremja:=round((t2 - t1)*24*60*60);
Label33.Caption := IntToStr(vremja)+ 'сек';
Label34.Caption := FloatToStr(razmer/vremja)+'байт/сек';
end;
//CBC zawifrovanie failov klju4om na 7 bait
procedure TForm1.Button11Click(Sender: TObject);
var
klu4:string;
vektor:string;
t1,t2:TDateTime;
vremja:integer;
razmer:integer;
begin
klu4:=Edit12.text;
while( Length(klu4)<8 ) do
klu4:=klu4 + '*';
Formirovanie_16_podklju4ei(klu4);
vektor:=Edit1.text;
while( Length(vektor)<8 ) do
vektor:=vektor+ '0';
t1:=Time;
if Form1.RadioButton10.Checked=true then
begin
Wifrovanie_CBC('20.txt','DES_crypted\Z_20_7_CBС.txt',vektor);
razmer:=1024*20;
end;
if Form1.RadioButton9.Checked=true then
begin
Wifrovanie_CBC('50.txt','DES_crypted\Z_50_7_CBС.txt',vektor);
razmer:=1024*50;
end;
if Form1.RadioButton8.Checked=true then
begin
Wifrovanie_CBC('100.txt','DES_crypted\Z_100_7_CBС.txt',vektor);
razmer:=1024*100;
end;
if Form1.RadioButton7.Checked=true then
begin
Wifrovanie_CBC('500.txt','DES_crypted\Z_500_7_CBС.txt',vektor);
razmer:=1024*500;
end;
if Form1.RadioButton6.Checked=true then
begin
Wifrovanie_CBC('1.txt','DES_crypted\Z_1_7_CBС.txt',vektor);
razmer:=1024*1024;
end;
t2:=Time;
vremja:=round((t2 - t1)*24*60*60)+1;
Label33.Caption := IntToStr(vremja-1)+ 'сек';
Label34.Caption := FloatToStr(razmer/vremja-1)+'байт/сек';
end;
//CBC raswifrovanie failov klju4om na 7 bait
procedure TForm1.Button12Click(Sender: TObject);
var
klu4:string;
vektor:string;
t1,t2:TDateTime;
vremja:integer;
razmer:integer;
begin
klu4:=Edit12.text;
while( Length(klu4)<8 ) do
klu4:=klu4 + '*';
Formirovanie_16_podklju4ei(klu4);
vektor:=Edit1.text;
while( Length(vektor)<8 ) do
vektor:=vektor+ '0';
t1:=Time;
if Form1.RadioButton10.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_20_7_CBС.txt','DES_uncrypted\R_20_7_CBС.txt',vektor);
razmer:=1024*20;
end;
if Form1.RadioButton9.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_50_7_CBС.txt','DES_uncrypted\R_50_7_CBС.txt',vektor);
razmer:=1024*50;
end;
if Form1.RadioButton8.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_100_7_CBС.txt','DES_uncrypted\R_100_7_CBС.txt',vektor);
razmer:=1024*100;
end;
if Form1.RadioButton7.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_500_7_CBС.txt','DES_uncrypted\R_500_7_CBС.txt',vektor);
razmer:=1024*500;
end;
if Form1.RadioButton6.Checked=true then
begin
Raswifrovanie_CBC('DES_crypted\Z_1_7_CBС.txt','DES_uncrypted\R_1_7_CBС.txt',vektor);
razmer:=1024*1024;
end;
t2:=Time;
vremja:=round((t2 - t1)*24*60*60);
Label33.Caption := IntToStr(vremja)+ 'сек';
Label34.Caption := FloatToStr(razmer/vremja)+'байт/сек';
end;
//S4itivaem alfavit dlja RSA
procedure TForm1.FormCreate(Sender: TObject);
begin
alf:=Form1.Label38.Caption;
end;
//Generacija prostih 4isel s pomowiju reweta Eratosfena
procedure TForm1.Button13Click(Sender: TObject);
const
n = 5000;
var
a:array[2..n] of boolean;
i,j:integer;
begin
for i:=2 to n do
a[i] := false;
for i:=2 to n do
begin
if(a[i] = false) then
begin
j:=2;
while i*j<=n do
begin
a[i*j]:=true;
j:=j+1;
end;
end;
end;
ListBox4.Clear;
for i:=1 to n do
begin
if(a[i] = false) then
ListBox4.Items.Add(IntToStr(i));
end;
end;
//Generacija vozmognih variantov klju4a Ka
procedure TForm1.Button14Click(Sender: TObject);
var
i:integer;
f:int64;//4islo vzaimno prostih 4isel s N
N,P,Q:int64;
x,y:int64;
k:integer;
begin
P:=StrToInt(Edit5.Text);
Q:=StrToInt(Edit4.Text);
N:=Q*P;
//Vi4isljaem koli4estvo vzaimno prostih s N 4isel
f:=(P-1)*(Q-1);
//Vivodim vse vozmognie Ka
ListBox3.Clear;
k:=0;
for i:=(f div 2) to f do
begin
if(NOD(i,f,x,y)= 1) then
begin
ListBox3.Items.Add(IntToStr(i));
inc(k);
if k=100 then
break;
end;
end;
end;
//Zawifrovanie failov klju4om Ka
procedure TForm1.Button15Click(Sender: TObject);
var
Ka:int64;
Kb:int64;
Q,P:int64;
i:integer;
t1,t2:TDateTime;
vremja:integer;
razmer:integer;
begin
P:= StrToInt(Edit5.Text); //S4itivaem P
Q:= StrToInt(Edit4.Text); //S4itivaem Q
if(ListBox3.ItemIndex <> -1) then
begin
Ka:= StrToInt(ListBox3.Items[ListBox3.ItemIndex]);//Opredeljaem sly4ainim obrazom Ka
Kb := -1;
t1:=Time;
if Form1.RadioButton10.Checked=true then
begin
Wifrovanie_RSA(Ka, P, Q, '20RSA.txt','RSA_crypted\Z_20_RSA.txt',Kb);
razmer:=1024*20;
end;
if Form1.RadioButton9.Checked=true then
begin
Wifrovanie_RSA(Ka, P, Q, '50RSA.txt','RSA_crypted\Z_50_RSA.txt',Kb);
razmer:=1024*50;
end;
if Form1.RadioButton8.Checked=true then
begin
Wifrovanie_RSA(Ka, P, Q, '100RSA.txt','RSA_crypted\Z_100_RSA.txt',Kb);
razmer:=1024*100;
end;
if Form1.RadioButton7.Checked=true then
begin
Wifrovanie_RSA(Ka, P, Q, '500RSA.txt','RSA_crypted\Z_500_RSA.txt',Kb);
razmer:=1024*500;
end;
if Form1.RadioButton6.Checked=true then
begin
Wifrovanie_RSA(Ka, P, Q, '1RSA.txt','RSA_crypted\Z_1_RSA.txt',Kb);
razmer:=1024*1024;
end;
t2:=Time;
end;
Label13.Caption := IntToStr(Ka);; //Vivodin Ka
Label12.Caption := IntToStr(Kb); //Vivodim Kb
vremja:=round((t2 - (t1+0.0000001))*24*60*60*1000);
Label33.Caption := (IntToStr(vremja-round(0.0000001)))+ 'милисек';
Label34.Caption := FloatToStr((razmer/vremja)-0.0000001)+'байт/милисек';
end;
//Raswifrovat faili klju4om Ka1
procedure TForm1.Button16Click(Sender: TObject);
var
Ka:int64;
Kb:int64;
Q,P:int64;
i:integer;
ish_f,vihod_f:TextFile;
t1,t2:TDateTime;
vremja:integer;
razmer:integer;
begin
P:= StrToInt(Edit5.Text); //S4itivaem P
Q:= StrToInt(Edit4.Text); //S4itivaem Q
if(ListBox3.ItemIndex <> -1) then
begin
Ka:= StrToInt(ListBox3.Items[ListBox3.ItemIndex]);//Opredeljaem sly4ainim obrazom Ka
Kb:=StrToInt(Label12.Caption);
t1:=Time;
if Form1.RadioButton10.Checked=true then
begin
Raswifrovanie_RSA(Kb,P,Q,'RSA_crypted\Z_20_RSA.txt','RSA_uncrypted\R_20_RSA.txt');
razmer:=1024*20;
end;
if Form1.RadioButton9.Checked=true then
begin
Raswifrovanie_RSA(Kb,P,Q,'RSA_crypted\Z_50_RSA.txt','RSA_uncrypted\R_50_RSA.txt');
razmer:=1024*20;
end;
if Form1.RadioButton8.Checked=true then
begin
Raswifrovanie_RSA(Kb,P,Q,'RSA_crypted\Z_100_RSA.txt','RSA_uncrypted\R_100_RSA.txt');
razmer:=1024*20;
end;
if Form1.RadioButton7.Checked=true then
begin
Raswifrovanie_RSA(Kb,P,Q,'RSA_crypted\Z_500_RSA.txt','RSA_uncrypted\R_500_RSA.txt');
razmer:=1024*20;
end;
if Form1.RadioButton6.Checked=true then
begin
Raswifrovanie_RSA(Kb,P,Q,'RSA_crypted\Z_1_RSA.txt','RSA_uncrypted\R_1_RSA.txt');
razmer:=1024*20;
end;
t2:=Time;
end;
vremja:=round((t2 - t1)*24*60*60)+1;
Label33.Caption := IntToStr(vremja-1)+ 'милисек';
Label34.Caption := FloatToStr((razmer/vremja)-1)+'байт/сек';
end;
end.
Подключаемые модули
unit DES_ECB_CBC_unit;
interface
procedure Wifrovanie_ECB(nazv_ish_f:string;nazv_vih_f:string);
procedure Raswifrovanie_ECB(nazv_ish_f:string;nazv_vih_f:string);
procedure Wifrovanie_CBC(nazv_ish_f:string;nazv_vih_f:string;vektor:string);
procedure Raswifrovanie_CBC(nazv_ish_f:string;nazv_vih_f:string;vektor:string);
implementation
uses DES_unit;
procedure Wifrovanie_ECB(nazv_ish_f:string;nazv_vih_f:string);
var
i:integer;
ish_text,vihod_text:string;
bykva:byte;
ish_f,vihod_f:file of byte;
begin
assignfile(ish_f,nazv_ish_f);
reset(ish_f);
assignfile(vihod_f,nazv_vih_f);
rewrite(vihod_f);
while not EOF(ish_f) do
begin
read(ish_f,bykva);
ish_text:=ish_text+chr(bykva);
if Length(ish_text) = 8 then