Xreferat.com » Рефераты по информатике и программированию » Использование современных симметрических (DES) и асимметрических (RSA) алгоритмов шифрования

Использование современных симметрических (DES) и асимметрических (RSA) алгоритмов шифрования

20 21

29 12 28 17

01 15 23 26

05 18 31 10

02 08 24 14

32 27 03 09

19 13 30 06

22 11 04 25


Таким образом,


f(R(i-1), K(i)) = P(S1(B(1)),...S8(B(8)))

Чтобы завершить описание алгоритма шифрования данных, осталось привести алгоритм получения 48-битовых ключей К(i), i=1...16. На каждой итерации используется новое значение ключа K(i), которое вычисляется из начального ключа K. K представляет собой 64-битовый блок с восемью битами контроля по четности, расположенными в позициях 8,16,24,32,40,48,56,64.

Для удаления контрольных битов и перестановки остальных используется функция G первоначальной подготовки ключа (табл.6).


Таблица 6

Матрица G первоначальной подготовки ключа

57 49 41 33 25 17 09

01 58 50 42 34 26 18

10 02 59 51 43 35 27

19 11 03 60 52 44 36

63 55 47 39 31 23 15

07 62 54 46 38 30 22

14 06 61 53 45 37 29

21 13 05 28 20 12 04


Результат преобразования G(K) разбивается на два 28-битовых блока C(0) и D(0), причем C(0) будет состоять из битов 57, 49, ..., 44, 36 ключа K, а D(0) будет состоять из битов 63, 55, ..., 12, 4 ключа K. После определения C(0) и D(0) рекурсивно определяются C(i) и D(i), i=1...16. Для этого применяют циклический сдвиг влево на один или два бита в зависимости от номера итерации, как показано в табл.7.

Таблица 7

Таблица сдвигов для вычисления ключа

Номер итерации

Сдвиг (бит)


01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16


1

1

2

2

2

2

2

2

1

2

2

2

2

2

2

1




Полученное значение вновь "перемешивается" в соответствии с матрицей H (табл.8).


Таблица 8:

Матрица H завершающей обработки ключа

14 17 11 24 01 05

03 28 15 06 21 10

23 19 12 04 26 08

16 07 27 20 13 02

41 52 31 37 47 55

30 40 51 45 33 48

44 49 39 56 34 53

46 42 50 36 29 32

Ключ K(i) будет состоять из битов 14, 17, ..., 29, 32 последовательности C(i)D(i). Таким образом:


K(i) = H(C(i)D(i))


Блок-схема алгоритма вычисления ключа приведена на рис.4.


Использование современных симметрических (DES) и асимметрических (RSA) алгоритмов шифрования

Рис.4. Блок-схема алгоритма вычисления ключа K(i)


Восстановление исходного текста осуществляется по такому же алгоритму, что и для шифрования, однако вначале используется ключ
K(16), затем - K(15) и так далее.

Исходные данные


Для шифра RSA использовался алфавит

0123456789@абвгдеёжзиклмнопрстуфхцчшщъыьэюя

Текст в файлах состоит из повторений фраз

В миску кашу со стен соскребите

в@миску@кашей@


Текст программы


unit main;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, ComCtrls,DES_unit,Podkluchi_unit,DES_ECB_CBC_unit,RSA_unit;


type

TForm1 = class(TForm)

Button17: TButton;

Label28: TLabel;

Label29: TLabel;

Label30: TLabel;

Label31: TLabel;

Label32: TLabel;

Label33: TLabel;

Label34: TLabel;

Edit10: TEdit;

Edit11: TEdit;

Edit12: TEdit;

Button18: TButton;

Button19: TButton;

Button20: TButton;

Button21: TButton;

Button22: TButton;

Edit1: TEdit;

Button1: TButton;

Button2: TButton;

Button3: TButton;

Button4: TButton;

Button5: TButton;

Button6: TButton;

Label5: TLabel;

Button7: TButton;

Button8: TButton;

RadioButton6: TRadioButton;

RadioButton7: TRadioButton;

RadioButton8: TRadioButton;

RadioButton9: TRadioButton;

RadioButton10: TRadioButton;

Button9: TButton;

Edit4: TEdit;

Edit5: TEdit;

ListBox3: TListBox;

Button10: TButton;

ListBox4: TListBox;

Label12: TLabel;

Label13: TLabel;

Label14: TLabel;

Label15: TLabel;

Label36: TLabel;

Label37: TLabel;

Label38: TLabel;

GroupBox1: TGroupBox;

GroupBox2: TGroupBox;

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

procedure Button3Click(Sender: TObject);

procedure Button4Click(Sender: TObject);

procedure Button5Click(Sender: TObject);

procedure Button6Click(Sender: TObject);

procedure Button7Click(Sender: TObject);

procedure Button8Click(Sender: TObject);

procedure Button9Click(Sender: TObject);

procedure Button10Click(Sender: TObject);

procedure Button11Click(Sender: TObject);

procedure Button12Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure Button13Click(Sender: TObject);

procedure Button14Click(Sender: TObject);

procedure Button15Click(Sender: TObject);

procedure Button16Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;


var

Form1: TForm1;


implementation


{$R *.dfm}

//Zawifrovanie failov klju4om na 5 bait

procedure TForm1.Button1Click(Sender: TObject);

var

klu4:string;

t1,t2:TDateTime;

vremja:integer;

razmer:integer;

begin

klu4:=Edit10.text;

while( Length(klu4)<8 ) do

klu4:=klu4+'0';

Formirovanie_16_podklju4ei(klu4);

razmer:=0;

t1:=Time;


if Form1.RadioButton10.Checked=true then

begin

Wifrovanie_ECB('20.txt','DES_cryptedZ_20_5_ECB.txt');

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Wifrovanie_ECB('50.txt','DES_cryptedZ_50_5_ECB.txt');

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Wifrovanie_ECB('100.txt','DES_cryptedZ_100_5_ECB.txt');

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Wifrovanie_ECB('500.txt','DES_cryptedZ_500_5_ECB.txt');

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Wifrovanie_ECB('1.txt','DES_cryptedZ_1_5_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;


//Raswifrovanie failov klju4om na 5 bait

procedure TForm1.Button2Click(Sender: TObject);

var

klu4:string;

t1,t2:TDateTime;

vremja:integer;

razmer:integer;

begin

klu4:=Edit10.text;

razmer:=0;

while( Length(klu4)<8 ) do

klu4:=klu4+'0';

Formirovanie_16_podklju4ei(klu4);


t1:=Time;


if Form1.RadioButton10.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_20_5_ECB.txt','DES_uncryptedR_20_5_ECB.txt');

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_50_5_ECB.txt','DES_uncryptedR_50_5_ECB.txt');

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_100_5_ECB.txt','DES_uncryptedR_100_5_ECB.txt');

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_500_5_ECB.txt','DES_uncryptedR_500_5_ECB.txt');

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_1_5_ECB.txt','DES_uncryptedR_1_5_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;


//Zawifrovanie failov klju4om na 6 bait

procedure TForm1.Button3Click(Sender: TObject);

var

klu4:string;

t1,t2:TDateTime;

vremja:integer;

razmer:integer;

begin

klu4:=Edit11.text;

while( Length(klu4)<8 ) do

klu4:=klu4+'0';

Formirovanie_16_podklju4ei(klu4);


t1:=Time;


if Form1.RadioButton10.Checked=true then

begin

Wifrovanie_ECB('20.txt','DES_cryptedZ_20_6_ECB.txt');

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Wifrovanie_ECB('50.txt','DES_cryptedZ_50_6_ECB.txt');

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Wifrovanie_ECB('100.txt','DES_cryptedZ_100_6_ECB.txt');

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Wifrovanie_ECB('500.txt','DES_cryptedZ_500_6_ECB.txt');

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Wifrovanie_ECB('1.txt','DES_cryptedZ_1_6_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;


//Raswifrovanie failov klju4om na 6 bait

procedure TForm1.Button4Click(Sender: TObject);

var

klu4:string;

t1,t2:TDateTime;

vremja:integer;

razmer:integer;

begin

klu4:=Edit11.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_cryptedZ_20_6_ECB.txt','DES_uncryptedR_20_6_ECB.txt');

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_50_6_ECB.txt','DES_uncryptedR_50_6_ECB.txt');

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_100_6_ECB.txt','DES_uncryptedR_100_6_ECB.txt');

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_500_6_ECB.txt','DES_uncryptedR_500_6_ECB.txt');

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_1_6_ECB.txt','DES_uncryptedR_1_6_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;


//Zawifrovanie failov klju4om na 7 bait

procedure TForm1.Button5Click(Sender: TObject);

var

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

Wifrovanie_ECB('20.txt','DES_cryptedZ_20_7_ECB.txt');

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Wifrovanie_ECB('50.txt','DES_cryptedZ_50_7_ECB.txt');

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Wifrovanie_ECB('100.txt','DES_cryptedZ_100_7_ECB.txt');

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Wifrovanie_ECB('500.txt','DES_cryptedZ_500_7_ECB.txt');

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Wifrovanie_ECB('1.txt','DES_cryptedZ_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;


//Raswifrovanie failov klju4om na 7 bait

procedure TForm1.Button6Click(Sender: TObject);

var

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_cryptedZ_20_7_ECB.txt','DES_uncryptedR_20_7_ECB.txt');

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_50_7_ECB.txt','DES_uncryptedR_50_7_ECB.txt');

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_100_7_ECB.txt','DES_uncryptedR_100_7_ECB.txt');

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_500_7_ECB.txt','DES_uncryptedR_500_7_ECB.txt');

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Raswifrovanie_ECB('DES_cryptedZ_1_7_ECB.txt','DES_uncryptedR_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_cryptedZ_20_5_CBС.txt',vektor);

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Wifrovanie_CBC('50.txt','DES_cryptedZ_50_5_CBС.txt',vektor);

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Wifrovanie_CBC('100.txt','DES_cryptedZ_100_5_CBС.txt',vektor);

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Wifrovanie_CBC('500.txt','DES_cryptedZ_500_5_CBС.txt',vektor);

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Wifrovanie_CBC('1.txt','DES_cryptedZ_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_cryptedZ_20_5_CBС.txt','DES_uncryptedR_20_5_CBС.txt',vektor);

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Raswifrovanie_CBC('DES_cryptedZ_50_5_CBС.txt','DES_uncryptedR_50_5_CBС.txt',vektor);

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Raswifrovanie_CBC('DES_cryptedZ_100_5_CBС.txt','DES_uncryptedR_100_5_CBС.txt',vektor);

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Raswifrovanie_CBC('DES_cryptedZ_500_5_CBС.txt','DES_uncryptedR_500_5_CBС.txt',vektor);

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Raswifrovanie_CBC('DES_cryptedZ_1_5_CBС.txt','DES_uncryptedR_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_cryptedZ_20_6_CBС.txt',vektor);

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Wifrovanie_CBC('50.txt','DES_cryptedZ_50_6_CBС.txt',vektor);

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Wifrovanie_CBC('100.txt','DES_cryptedZ_100_6_CBС.txt',vektor);

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Wifrovanie_CBC('500.txt','DES_cryptedZ_500_6_CBС.txt',vektor);

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Wifrovanie_CBC('1.txt','DES_cryptedZ_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_cryptedZ_20_6_CBС.txt','DES_uncryptedR_20_6_CBС.txt',vektor);

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Raswifrovanie_CBC('DES_cryptedZ_50_6_CBС.txt','DES_uncryptedR_50_6_CBС.txt',vektor);

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Raswifrovanie_CBC('DES_cryptedZ_100_6_CBС.txt','DES_uncryptedR_100_6_CBС.txt',vektor);

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Raswifrovanie_CBC('DES_cryptedZ_500_6_CBС.txt','DES_uncryptedR_500_6_CBС.txt',vektor);

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Raswifrovanie_CBC('DES_cryptedZ_1_6_CBС.txt','DES_uncryptedR_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_cryptedZ_20_7_CBС.txt',vektor);

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Wifrovanie_CBC('50.txt','DES_cryptedZ_50_7_CBС.txt',vektor);

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Wifrovanie_CBC('100.txt','DES_cryptedZ_100_7_CBС.txt',vektor);

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Wifrovanie_CBC('500.txt','DES_cryptedZ_500_7_CBС.txt',vektor);

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Wifrovanie_CBC('1.txt','DES_cryptedZ_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_cryptedZ_20_7_CBС.txt','DES_uncryptedR_20_7_CBС.txt',vektor);

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Raswifrovanie_CBC('DES_cryptedZ_50_7_CBС.txt','DES_uncryptedR_50_7_CBС.txt',vektor);

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Raswifrovanie_CBC('DES_cryptedZ_100_7_CBС.txt','DES_uncryptedR_100_7_CBС.txt',vektor);

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Raswifrovanie_CBC('DES_cryptedZ_500_7_CBС.txt','DES_uncryptedR_500_7_CBС.txt',vektor);

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Raswifrovanie_CBC('DES_cryptedZ_1_7_CBС.txt','DES_uncryptedR_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_cryptedZ_20_RSA.txt',Kb);

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Wifrovanie_RSA(Ka, P, Q, '50RSA.txt','RSA_cryptedZ_50_RSA.txt',Kb);

razmer:=1024*50;

end;

if Form1.RadioButton8.Checked=true then

begin

Wifrovanie_RSA(Ka, P, Q, '100RSA.txt','RSA_cryptedZ_100_RSA.txt',Kb);

razmer:=1024*100;

end;

if Form1.RadioButton7.Checked=true then

begin

Wifrovanie_RSA(Ka, P, Q, '500RSA.txt','RSA_cryptedZ_500_RSA.txt',Kb);

razmer:=1024*500;

end;

if Form1.RadioButton6.Checked=true then

begin

Wifrovanie_RSA(Ka, P, Q, '1RSA.txt','RSA_cryptedZ_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_cryptedZ_20_RSA.txt','RSA_uncryptedR_20_RSA.txt');

razmer:=1024*20;

end;

if Form1.RadioButton9.Checked=true then

begin

Raswifrovanie_RSA(Kb,P,Q,'RSA_cryptedZ_50_RSA.txt','RSA_uncryptedR_50_RSA.txt');

razmer:=1024*20;

end;

if Form1.RadioButton8.Checked=true then

begin

Raswifrovanie_RSA(Kb,P,Q,'RSA_cryptedZ_100_RSA.txt','RSA_uncryptedR_100_RSA.txt');

razmer:=1024*20;

end;

if Form1.RadioButton7.Checked=true then

begin

Raswifrovanie_RSA(Kb,P,Q,'RSA_cryptedZ_500_RSA.txt','RSA_uncryptedR_500_RSA.txt');

razmer:=1024*20;

end;

if Form1.RadioButton6.Checked=true then

begin

Raswifrovanie_RSA(Kb,P,Q,'RSA_cryptedZ_1_RSA.txt','RSA_uncryptedR_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

begin

vihod_text:= Kodirovat(ish_text);

for i:=1 to 8 do

begin

bykva:=byte(vihod_text[i]);

write(vihod_f,bykva);

end;

ish_text := '';

end;

end;


if(Length(ish_text) <> 0) then

begin

while length(ish_text)<8 do

ish_text:=ish_text+'0';

vihod_text := Kodirovat(ish_text);

for i:=1 to 8 do

begin

bykva:=byte(vihod_text[i]);

write(vihod_f,bykva);

end;

end;


end;

procedure Raswifrovanie_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

begin

vihod_text:= Raskodirovat(ish_text);

for i:=1 to 8 do

begin

bykva:=byte(vihod_text[i]);

write(vihod_f,bykva);

end;

ish_text := '';

end;

end;

if(Length(ish_text) <> 0) then

begin

while length(ish_text)<8 do

ish_text:=ish_text+'0';

vihod_text := Raskodirovat(ish_text);

for i:=1 to 8 do

begin

bykva:=byte(vihod_text[i]);

write(vihod_f,bykva);

end;

end;


end;


procedure Wifrovanie_CBC(nazv_ish_f:string;nazv_vih_f:string;vektor: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

begin

for i:=1 to 8 do

ish_text[i]:=chr(ord(ish_text[i]) xor ord(vektor[i]));

vihod_text:= Kodirovat(ish_text);

vektor := vihod_text;

for i:=1 to 8 do

begin

bykva:=byte(vihod_text[i]);

write(vihod_f,bykva);

end;

ish_text := '';

end;

end;


if(Length(ish_text) <> 0) then

begin

while length(ish_text)<8 do

ish_text:=ish_text+'0';

for i:=1 to 8 do

ish_text[i] := chr(ord(ish_text[i]) xor ord(vektor[i]));

vihod_text := Kodirovat(ish_text);

for i:=1 to 8 do

begin

bykva:=byte(vihod_text[i]);

write(vihod_f,bykva);

end;

end;


end;


procedure Raswifrovanie_CBC(nazv_ish_f:string;nazv_vih_f:string;vektor:string);

var

i:integer;

ish_text,vihod_text,tmp: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

begin

tmp := ish_text;

vihod_text:= Raskodirovat(ish_text);

for i:=1 to 8 do

vihod_text[i] := chr(ord(vihod_text[i]) xor ord(vektor[i]));

vektor := tmp;

for i:=1 to 8 do

begin

bykva:=byte(vihod_text[i]);

write(vihod_f,bykva);

end;

ish_text := '';

end;

end;


if(Length(ish_text) <> 0) then

begin

while length(ish_text)<8 do

ish_text:=ish_text+'0';

tmp := ish_text;

vihod_text:= Raskodirovat(ish_text);

for i:=1 to 8 do

vihod_text[i] := chr(ord(vihod_text[i]) xor ord(vektor[i]));

vektor := tmp;

for i:=1 to 8 do

begin

bykva:=byte(vihod_text[i]);

write(vihod_f,bykva);

end;

end;


end;


end.


unit DES_unit;


interface


type odnom_1_64=array[1..64] of byte;

type odnom_1_56=array[1..56] of byte;

type odnom_1_48=array[1..48] of byte;

type odnom_1_32=array[1..32] of byte;

type dvym_1_17_1_32=array[1..17,1..32] of byte;

type dvym_1_17_1_28=array[1..17,1..28] of byte;

type dvym_1_16_1_48=array[1..16,1..48] of byte;//16 подключей


procedure Perestanovka_IP (var Klju4_64_posle_IP: odnom_1_64);

procedure Perestanovka_E (n:integer; Tekst_32_do_E: dvym_1_17_1_32; var Tekst_48_posle_E: odnom_1_48);

procedure Perestanovka_P(var Tekst_32_posle_P:odnom_1_32);

procedure S_Blok (e: odnom_1_48; var p: odnom_1_32);

procedure Perestanovka_IP_1 (var Tekst_64_posle_IP1: odnom_1_64);


procedure TextVBinarn (Tekst_bykv: string; var Tekst_64_binar: odnom_1_64);

procedure BinarnVText(Tekst_64_binar: odnom_1_64;var Tekst_bykv: string);

function Kodirovat(Ish_tekst_bykv:string):string;

function Raskodirovat(Wifr_tekst_bykv:string):string;


implementation


uses podkluchi_unit;


var

matrica_IP:array[1..64] of byte=(58, 50, 42, 34, 26, 18, 10, 02,

60, 52, 44, 36, 28, 20, 12, 04,

62, 54, 46, 38, 30, 22, 14, 06,

64, 56, 48, 40, 32, 24, 16, 08,

57, 49, 41, 33, 25, 17, 09, 01,

59, 51, 43, 35, 27, 19, 11, 03,

61, 53, 45, 37, 29, 21, 13, 05,

63, 55, 47, 39, 31, 23, 15, 07);

matrica_E:array[1..48] of byte=(32, 01, 02, 03, 04, 05,

04, 05, 06, 07, 08, 09,

08, 09, 10, 11, 12, 13,

12, 13, 14, 15, 16, 17,

16, 17, 18, 19, 20, 21,

20, 21, 22, 23, 24, 25,

24, 25, 26, 27, 28, 29,

28, 29, 30, 31, 32, 01);

matrica_P:array[1..32] of byte=(16, 07, 20, 21,

29, 12, 28, 17,

01, 15, 23, 26,

05, 18, 31, 10,

02, 08, 24, 14,

32, 27, 03, 09,

19, 13, 30, 06,

22, 11, 04, 25);

matrica_IP_1:array[1..64] of byte=(40, 08, 48, 16, 56, 24, 64, 32,

39, 07, 47, 15, 55, 23, 63, 31,

38, 06, 46, 14, 54, 22, 62, 30,

37, 05, 45, 13, 53, 21, 61, 29,

36, 04, 44, 12, 52, 20, 60, 28,

35, 03, 43, 11, 51, 19, 59, 27,

34, 02, 42, 10, 50, 18, 58, 26,

33, 01, 41, 09, 49, 17, 57, 25);

procedure Perestanovka_IP (var Klju4_64_posle_IP: odnom_1_64);

var Vrem_klju4_64: odnom_1_64;

i:integer;

begin

//Kopirivanie binarnogo predstavlenia

for i:=1 to 64 do

Vrem_klju4_64[i]:=Klju4_64_posle_IP[i];


//IP perestanovka

for i:=1 to 64 do

Klju4_64_posle_IP[i]:=Vrem_klju4_64[matrica_IP[i]];


end;


procedure Perestanovka_E (n:integer; Tekst_32_do_E: dvym_1_17_1_32; var Tekst_48_posle_E: odnom_1_48);

var i:integer;

begin


for i:=1 to 48 do

Tekst_48_posle_E[i]:=Tekst_32_do_E[n,matrica_E[i]];

end;

procedure Perestanovka_P(var Tekst_32_posle_P:odnom_1_32);

var i:integer;

Vrem_tekst_32:odnom_1_32;

begin


//Kopiy binarnogo predstavlenia

for i:=1 to 32 do

Vrem_tekst_32[i]:=Tekst_32_posle_P[i];


//P perestanovka bit

for i:=1 to 32 do

Tekst_32_posle_P[i]:=Vrem_tekst_32[matrica_P[i]];


end;


procedure S_Blok (e: odnom_1_48; var p: odnom_1_32);

var q,i,j:integer;//s4et4iki

k:integer;//4islo na perese4enii neobhodimoi stro4ki i stolbika

h:integer;

symma_2_krainih,symma_4_vnytrennih:integer;

s_blok:array[0..3,0..15] of byte;

B_dvym_8_6:array[1..8,1..6] of byte;

f:textfile;

begin


//Razbitie na 8 4astei po 6 bit

q:=0;

for i:=1 to 8 do

for j:=1 to 6 do

begin

q:=q+1;

B_dvym_8_6[i,j]:=e[q];

end;


//S4itivaem S blok

AssignFile(f,'S.txt');

Reset(f);


//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

for q:=1 to 8 do

begin

symma_2_krainih:=B_dvym_8_6[q,6]+B_dvym_8_6[q,1]*2;

symma_4_vnytrennih:=B_dvym_8_6[q,2]+2*B_dvym_8_6[q,3]+4*B_dvym_8_6[q,4]+8*B_dvym_8_6[q,5];

for i:=0 to 3 do

for j:=0 to 15 do

read(f,s_blok[i,j]);

k:=s_blok[symma_2_krainih,symma_4_vnytrennih];

h:=4*q;

for j:=1 to 4 do

begin

p[h]:=k mod 2;

k:=k div 2;

h:=h-1;

end

end;


closefile(f);


end;


procedure Perestanovka_IP_1 (var Tekst_64_posle_IP1: odnom_1_64);

var Vrem_tekst_64: odnom_1_64;

i:integer;

begin

//Kopiy binarnogo predstavlenia

for i:=1 to 64 do

Vrem_tekst_64[i]:=Tekst_64_posle_IP1[i];


//IP perestanovka bit

for i:=1 to 64 do

Tekst_64_posle_IP1[i]:=Vrem_tekst_64[matrica_IP_1[i]];


end;


//Perevodit text v binarnoe predstavlenie

procedure TextVBinarn (Tekst_bykv: string; var Tekst_64_binar: odnom_1_64);

var j,h,a,i:integer;

alfav_ASCII:array[1..8] of integer;

begin

//Perevod simvolov v ASCII-kodi

for i:=1 to 8 do

alfav_ASCII[i]:=ord(Tekst_bykv[i]);//vozvrawaet № simvola v ASC


//Perevod chisel v binarniy kod

for j:=1 to 8 do

begin

h:=8*j;

a:=alfav_AscII[j];

for i:=1 to 8 do

begin

Tekst_64_binar[h]:=a mod 2;

a:=a div 2;//sdvig vpravo na 1

h:=h-1;

end

end;


end;


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++

//Perevodit binarnoe predstavlenie v tekst

procedure BinarnVText(Tekst_64_binar: odnom_1_64;var Tekst_bykv: string);

var Vrem_tekst:string;

a,i,j:integer;

begin


Vrem_tekst:='';

for i:=1 to 8 do

begin

a:=0;

for j:=(i-1)*8+1 to i*8 do

a:= a*2+Tekst_64_binar[j];

Vrem_tekst:=concat(Vrem_tekst,char(a));//prilirljaet k s a

end;

Tekst_bykv:=Vrem_tekst;

end;

function Kodirovat(Ish_tekst_bykv:string):string;

var Ish_tekst_64_binar:odnom_1_64;

i,j:integer;

levaja,pravaja:dvym_1_17_1_32;

Tekst_48_posle_raswirenija:odnom_1_48;

B_tekst_32:odnom_1_32;

begin


TextVBinarn (Ish_tekst_bykv,Ish_tekst_64_binar);


Perestanovka_IP (Ish_tekst_64_binar);


//Delim na levyju i na pravyju 4asti

j:=0;

for i:=1 to 64 do

if i<33 then

levaja[1,i]:=Ish_tekst_64_binar[i]

else

begin

j:=j+1;

pravaja[1,j]:=Ish_tekst_64_binar[i];

end;


//16 rayndov wifrovanija

for i:=2 to 17 do

begin

for j:=1 to 32 do

levaja[i,j]:=pravaja[i-1,j];

Perestanovka_E(i-1,pravaja,Tekst_48_posle_raswirenija);

for j:=1 to 48 do

Tekst_48_posle_raswirenija[j]:=Tekst_48_posle_raswirenija[j] xor podklu4i[i-1,j];

s_blok(Tekst_48_posle_raswirenija,B_tekst_32);

Perestanovka_P(B_tekst_32);

for j:=1 to 32 do

pravaja[i,j]:=levaja[i-1,j] xor B_tekst_32[j];

end;


//!!!

//Menjaem mestami

for i:=1 to 32 do

begin

j:= pravaja[17][i];

pravaja[17][i] := levaja[17][i];

levaja[17][i] := j;

end;


//Skladivanie levoi i pravoi

j:=0;

for i:=1 to 64 do

if i<33 then

Ish_tekst_64_binar[i]:=levaja[17,i]

else

begin

j:=j+1;

Ish_tekst_64_binar[i]:=pravaja[17,j];

end;


Perestanovka_IP_1(Ish_tekst_64_binar);


BinarnVText(Ish_tekst_64_binar,Ish_tekst_bykv);


kodirovat:= Ish_tekst_bykv;

end;

function Raskodirovat(Wifr_tekst_bykv:string):string;

var Wifr_tekst_64_binar:odnom_1_64;

i,j:integer;

levaja,pravaja:dvym_1_17_1_32;

Tekst_48_posle_raswirenija:odnom_1_48;

B_tekst_32:odnom_1_32;

begin


TextVBinarn (Wifr_tekst_bykv,Wifr_tekst_64_binar);


Perestanovka_IP (Wifr_tekst_64_binar);


//Delim na levyju i na pravyju 4asti

j:=0;

for i:=1 to 64 do

if i<33 then

levaja[17,i]:=Wifr_tekst_64_binar[i]

else

begin

j:=j+1;

pravaja[17,j]:=Wifr_tekst_64_binar[i];

end;


//!!!!!!!!

//Menjaem mestami

for i:=1 to 32 do

begin

j:= pravaja[17][i];

pravaja[17][i]:=levaja[17][i];

levaja[17][i]:=j;

end;

//16 raundov wifrovanija

for i:=17 downto 2 do

begin

for j:=1 to 32 do

pravaja[i-1,j]:=levaja[i,j];

Perestanovka_E(i,levaja,Tekst_48_posle_raswirenija);

for j:=1 to 48 do

Tekst_48_posle_raswirenija[j]:=Tekst_48_posle_raswirenija[j] xor podklu4i[i-1,j];

s_blok(Tekst_48_posle_raswirenija,B_tekst_32);

Perestanovka_P(B_tekst_32);

for j:=1 to 32 do

levaja[i-1,j]:=pravaja[i,j] xor B_tekst_32[j];

end;


//Skladivanie levoi i pravoi

j:=0;

for i:=1 to 64 do

if i<33 then

Wifr_tekst_64_binar[i]:=levaja[1,i]

else

begin

j:=j+1;

Wifr_tekst_64_binar[i]:=pravaja[1,j];

end;


Perestanovka_IP_1(Wifr_tekst_64_binar);


BinarnVText(Wifr_tekst_64_binar,Wifr_tekst_bykv);

Raskodirovat:=Wifr_tekst_bykv;

end;


end.


unit Podkluchi_unit;


interface

uses DES_unit;


var

podklu4i:dvym_1_16_1_48;

matrica_PC1:array[1..56] of byte=(57, 49, 41, 33, 25, 17, 09,

01, 58, 50, 42, 34, 26, 18,

10, 02, 59, 51, 43, 35, 27,

19, 11, 03, 60, 52, 44, 36,

63, 55, 47, 39, 31, 23, 15,

07, 62, 54, 46, 38, 30, 22,

14, 06, 61, 53, 45, 37, 29,

21, 13, 05, 28, 20, 12, 04);

matrica_PC2:array[1..48] of byte=(14, 17, 11, 24, 01, 05,

03, 28, 15, 06, 21, 10,

23, 19, 12, 04, 26, 08,

16, 07, 27, 20, 13, 02,

41, 52, 31, 37, 47, 55,

30, 40, 51, 45, 33, 48,

44, 49, 39, 56, 34, 53,

46, 42, 50, 36, 29, 32);

matrica_sdvigov:array[1..16] of byte=(1,1,2,2,

2,2,2,2,

1,2,2,2,

2,2,2,1);


procedure Formirovanie_16_podklju4ei(Klju4_64:string);


implementation

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++

procedure Perestanovka_PC1(Klju4_64_do_PC1: odnom_1_64; var Klju4_64_posle_PC1:odnom_1_56);

var i:integer;

begin

for i:=1 to 56 do

Klju4_64_posle_PC1[i]:=Klju4_64_do_PC1[matrica_PC1[i]];

end;


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++

procedure Perestanovka_PC2(Klju4_56_do_PC2:odnom_1_56; k:integer);

var i:integer;

begin

for i:=1 to 48 do

podklu4i[k][i]:=Klju4_56_do_PC2[matrica_PC2[i]];

end;


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++

procedure Formirovanie_16_podklju4ei(Klju4_64:string);

var

i,j,k:integer;

c_vrem,d_vrem: dvym_1_17_1_28;

c: dvym_1_17_1_28;

d: dvym_1_17_1_28;

c_d: odnom_1_56;

Klju4ik_64:odnom_1_64;

Klju4ik_56:odnom_1_56;

begin


TextVBinarn (Klju4_64,Klju4ik_64);//ключ из 64 в 64


Perestanovka_PC1(Klju4ik_64,Klju4ik_56);//битовый ключ 64, битовый ключ 56


//Razbivaem na c i d

j:=0;

for i:=1 to 56 do

if i<29 then

c[1,i]:=Klju4ik_56[i]

else

begin

j:=j+1;

d[1,j]:=Klju4ik_56[i];

end;


//Kopiryem с i d vo vremennie c_vrem i d_vrem

for j:=1 to 28 do

begin

c_vrem[1,j]:=c[1,j];

d_vrem[1,j]:=d[1,j];

end;


//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

//Delaem sdvigi LSi

for i:=2 to 17 do

begin

k:=0;

for j:=1 to 28 do

if j+matrica_sdvigov[i-1]>28 then

begin

k:=k+1;

c[i,j]:=c_vrem[i-1,k];

d[i,j]:=d_vrem[i-1,k];

c_vrem[i,j]:=c[i,j];

d_vrem[i,j]:=d[i,j];

end

else

begin

c[i,j]:=c_vrem[i-1,j+matrica_sdvigov[i-1]];

d[i,j]:=d_vrem[i-1,j+matrica_sdvigov[i-1]];

c_vrem[i,j]:=c[i,j];

d_vrem[i,j]:=d[i,j];

Если Вам нужна помощь с академической работой (курсовая, контрольная, диплом, реферат и т.д.), обратитесь к нашим специалистам. Более 90000 специалистов готовы Вам помочь.
Бесплатные корректировки и доработки. Бесплатная оценка стоимости работы.

Поможем написать работу на аналогичную тему

Получить выполненную работу или консультацию специалиста по вашему учебному проекту
Нужна помощь в написании работы?
Мы - биржа профессиональных авторов (преподавателей и доцентов вузов). Пишем статьи РИНЦ, ВАК, Scopus. Помогаем в публикации. Правки вносим бесплатно.

Похожие рефераты: