Розробка програми „ Криптоаналiз ”

Автор работы: Пользователь скрыл имя, 29 Ноября 2013 в 00:04, курсовая работа

Описание работы

Шифрування - спосіб перетворення відкритої інформації в закриту і назад. Застосовується для зберігання важливої ​​інформації в ненадійних джерелах або передачі її по незахищених каналах зв'язку. Згідно ГОСТ 28147-89, шифрування підрозділяється на процес зашифровування і розшифрування. Залежно від алгоритму перетворення даних, методи шифрування поділяються на гарантованої або тимчасової криптостойкости. Мета роботи: Розробити програму шифрування/дешифрування. Для досягнення поставленої мети в роботі вирішувалися наступні завдання:
розробити ескізний і технічний проект програми;
розробити робочий проект програми.

Содержание работы

Вступ………. 3
РОЗДIЛ I. Загальнi вiдомостi 4
1.1.Загальнi вiдомостi про AES 4
РОЗДIЛ II. Розробка проекту програми 6
2.1.Опис елементiв програми 6
2.2.Шифрування та процедури.. 9
2.3.Алгоротми та криптостiйкicть… 13
2.4.Тестування програми …. 17
Висновки….. 19
Список використаних джерел….. 20

Файлы: 1 файл

Документ Microsoft Word.docx

— 254.52 Кб (Скачать файл)

W2:= InverseTable [Byte(T0 [0] shr 16)]; W3:= InverseTable [Byte(T0 [3] shr 24)];

T1 [2]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[30];

W0:= InverseTable [Byte(T0 [3])]; W1:= InverseTable [Byte(T0 [2] shr 8)];

W2:= InverseTable [Byte(T0 [1] shr 16)]; W3:= InverseTable [Byte(T0 [0] shr 24)];

T1 [3]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[31];

W0:= InverseTable [Byte(T1 [0])]; W1:= InverseTable [Byte(T1 [3] shr 8)];

W2:= InverseTable [Byte(T1 [2] shr 16)]; W3:= InverseTable [Byte(T1 [1] shr 24)];

T0 [0]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[24];

W0:= InverseTable [Byte(T1 [1])]; W1:= InverseTable [Byte(T1 [0] shr 8)];

W2:= InverseTable [Byte(T1 [3] shr 16)]; W3:= InverseTable [Byte(T1 [2] shr 24)];

T0 [1]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[25];

W0:= InverseTable [Byte(T1 [2])]; W1:= InverseTable [Byte(T1 [1] shr 8)];

W2:= InverseTable [Byte(T1 [0] shr 16)]; W3:= InverseTable [Byte(T1 [3] shr 24)];

T0 [2]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[26];

W0:= InverseTable [Byte(T1 [3])]; W1:= InverseTable [Byte(T1 [2] shr 8)];

W2:= InverseTable [Byte(T1 [1] shr 16)]; W3:= InverseTable [Byte(T1 [0] shr 24)];

T0 [3]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[27];

W0:= InverseTable [Byte(T0 [0])]; W1:= InverseTable [Byte(T0 [3] shr 8)];

W2:= InverseTable [Byte(T0 [2] shr 16)]; W3:= InverseTable [Byte(T0 [1] shr 24)];

T1 [0]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[20];

W0:= InverseTable [Byte(T0 [1])]; W1:= InverseTable [Byte(T0 [0] shr 8)];

W2:= InverseTable [Byte(T0 [3] shr 16)]; W3:= InverseTable [Byte(T0 [2] shr 24)];

T1 [1]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[21];

W0:= InverseTable [Byte(T0 [2])]; W1:= InverseTable [Byte(T0 [1] shr 8)];

W2:= InverseTable [Byte(T0 [0] shr 16)]; W3:= InverseTable [Byte(T0 [3] shr 24)];

T1 [2]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[22];

W0:= InverseTable [Byte(T0 [3])]; W1:= InverseTable [Byte(T0 [2] shr 8)];

W2:= InverseTable [Byte(T0 [1] shr 16)]; W3:= InverseTable [Byte(T0 [0] shr 24)];

T1 [3]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[23];

W0:= InverseTable [Byte(T1 [0])]; W1:= InverseTable [Byte(T1 [3] shr 8)];

W2:= InverseTable [Byte(T1 [2] shr 16)]; W3:= InverseTable [Byte(T1 [1] shr 24)];

T0 [0]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[16];

W0:= InverseTable [Byte(T1 [1])]; W1:= InverseTable [Byte(T1 [0] shr 8)];

W2:= InverseTable [Byte(T1 [3] shr 16)]; W3:= InverseTable [Byte(T1 [2] shr 24)];

T0 [1]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[17];

W0:= InverseTable [Byte(T1 [2])]; W1:= InverseTable [Byte(T1 [1] shr 8)];

W2:= InverseTable [Byte(T1 [0] shr 16)]; W3:= InverseTable [Byte(T1 [3] shr 24)];

T0 [2]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[18];

W0:= InverseTable [Byte(T1 [3])]; W1:= InverseTable [Byte(T1 [2] shr 8)];

W2:= InverseTable [Byte(T1 [1] shr 16)]; W3:= InverseTable [Byte(T1 [0] shr 24)];

T0 [3]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[19];

W0:= InverseTable [Byte(T0 [0])]; W1:= InverseTable [Byte(T0 [3] shr 8)];

W2:= InverseTable [Byte(T0 [2] shr 16)]; W3:= InverseTable [Byte(T0 [1] shr 24)];

T1 [0]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[12];

W0:= InverseTable [Byte(T0 [1])]; W1:= InverseTable [Byte(T0 [0] shr 8)];

W2:= InverseTable [Byte(T0 [3] shr 16)]; W3:= InverseTable [Byte(T0 [2] shr 24)];

T1 [1]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[13];

W0:= InverseTable [Byte(T0 [2])]; W1:= InverseTable [Byte(T0 [1] shr 8)];

W2:= InverseTable [Byte(T0 [0] shr 16)]; W3:= InverseTable [Byte(T0 [3] shr 24)];

T1 [2]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[14];

W0:= InverseTable [Byte(T0 [3])]; W1:= InverseTable [Byte(T0 [2] shr 8)];

W2:= InverseTable [Byte(T0 [1] shr 16)]; W3:= InverseTable [Byte(T0 [0] shr 24)];

T1 [3]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[15];

W0:= InverseTable [Byte(T1 [0])]; W1:= InverseTable [Byte(T1 [3] shr 8)];

W2:= InverseTable [Byte(T1 [2] shr 16)]; W3:= InverseTable [Byte(T1 [1] shr 24)];

T0 [0]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[8];

W0:= InverseTable [Byte(T1 [1])]; W1:= InverseTable [Byte(T1 [0] shr 8)];

W2:= InverseTable [Byte(T1 [3] shr 16)]; W3:= InverseTable [Byte(T1 [2] shr 24)];

T0 [1]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[9];

W0:= InverseTable [Byte(T1 [2])]; W1:= InverseTable [Byte(T1 [1] shr 8)];

W2:= InverseTable [Byte(T1 [0] shr 16)]; W3:= InverseTable [Byte(T1 [3] shr 24)];

T0 [2]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[10];

W0:= InverseTable [Byte(T1 [3])]; W1:= InverseTable [Byte(T1 [2] shr 8)];

W2:= InverseTable [Byte(T1 [1] shr 16)]; W3:= InverseTable [Byte(T1 [0] shr 24)];

T0 [3]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[11];

W0:= InverseTable [Byte(T0 [0])]; W1:= InverseTable [Byte(T0 [3] shr 8)];

W2:= InverseTable [Byte(T0 [2] shr 16)]; W3:= InverseTable [Byte(T0 [1] shr 24)];

T1 [0]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[4];

W0:= InverseTable [Byte(T0 [1])]; W1:= InverseTable [Byte(T0 [0] shr 8)];

W2:= InverseTable [Byte(T0 [3] shr 16)]; W3:= InverseTable [Byte(T0 [2] shr 24)];

T1 [1]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[5];

W0:= InverseTable [Byte(T0 [2])]; W1:= InverseTable [Byte(T0 [1] shr 8)];

W2:= InverseTable [Byte(T0 [0] shr 16)]; W3:= InverseTable [Byte(T0 [3] shr 24)];

T1 [2]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[6];

W0:= InverseTable [Byte(T0 [3])]; W1:= InverseTable [Byte(T0 [2] shr 8)];

W2:= InverseTable [Byte(T0 [1] shr 16)]; W3:= InverseTable [Byte(T0 [0] shr 24)];

T1 [3]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[7];

 

W0:= LastInverseTable [Byte(T1 [0])]; W1:= LastInverseTable [Byte(T1 [3] shr 8)];

W2:= LastInverseTable [Byte(T1 [2] shr 16)]; W3:= LastInverseTable [Byte(T1 [1] shr 24)];

T0 [0]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[0];

W0:= LastInverseTable [Byte(T1 [1])]; W1:= LastInverseTable [Byte(T1 [0] shr 8)];

W2:= LastInverseTable [Byte(T1 [3] shr 16)]; W3:= LastInverseTable [Byte(T1 [2] shr 24)];

T0 [1]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[1];

W0:= LastInverseTable [Byte(T1 [2])]; W1:= LastInverseTable [Byte(T1 [1] shr 8)];

W2:= LastInverseTable [Byte(T1 [0] shr 16)]; W3:= LastInverseTable [Byte(T1 [3] shr 24)];

T0 [2]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[2];

W0:= LastInverseTable [Byte(T1 [3])]; W1:= LastInverseTable [Byte(T1 [2] shr 8)];

W2:= LastInverseTable [Byte(T1 [1] shr 16)]; W3:= LastInverseTable [Byte(T1 [0] shr 24)];

T0 [3]:= (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[3];

PLongWord (@OutBuf[0])^:= T0 [0]; PLongWord (@OutBuf[4])^:= T0 [1];

PLongWord (@OutBuf[8])^:= T0 [2]; PLongWord (@OutBuf[12])^:= T0 [3];

end;

procedure EncryptAESStreamECB (Source: TStream; Count: cardinal;

const Key: TAESKey128; Dest: TStream);

var

ExpandedKey: TAESExpandedKey128;

begin

ExpandAESKeyForEncryption (Key, ExpandedKey);

EncryptAESStreamECB (Source, Count, ExpandedKey, Dest);

end;

procedure EncryptAESStreamECB (Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey128; Dest: TStream);

var

TempIn, TempOut: TAESBuffer;

Done: cardinal;

st: TStringStream;

tick: integer;

begin

st:= TStringStream. Create('');

if Count = 0 then

begin

Source. Position:= 0;

Count:= Source. Size;

end

else Count:= Min (Count, Source. Size – Source. Position);

if Count = 0 then exit;

while Count >= SizeOf(TAESBuffer) do

begin

Done:= Source. Read (TempIn, SizeOf(TempIn)); // Считываемданныеизпотока

if Done < SizeOf(TempIn) then

raise EStreamError. Create(SReadError);

EncryptAES (TempIn, ExpandedKey, TempOut);

if flag = false then

begin

 

FmStop. EditIn. Text:= IntToHex (TempIn[0], 2)+IntToHex (TempIn[1], 2)+

IntToHex (TempIn[2], 2)+IntToHex (TempIn[3], 2)+IntToHex (TempIn[4], 2)+

IntToHex (TempIn[5], 2)+IntToHex (TempIn[6], 2)+IntToHex (TempIn[7], 2)+

IntToHex (TempIn[8], 2)+IntToHex (TempIn[9], 2)+IntToHex (TempIn[10], 2)+

IntToHex (TempIn[11], 2)+IntToHex (TempIn[12], 2)+IntToHex (TempIn[13], 2)+

IntToHex (TempIn[14], 2)+IntToHex (TempIn[15], 2);

 

FmStop. EditOut. Text:= IntToHex (TempOut[0], 2)+IntToHex (TempOut[1], 2)+

IntToHex (TempOut[2], 2)+IntToHex (TempOut[3], 2)+IntToHex (TempOut[4], 2)+

IntToHex (TempOut[5], 2)+IntToHex (TempOut[6], 2)+IntToHex (TempOut[7], 2)+

IntToHex (TempOut[8], 2)+IntToHex (TempOut[9], 2)+IntToHex (TempOut[10], 2)+

IntToHex (TempOut[11], 2)+IntToHex (TempOut[12], 2)+IntToHex (TempOut[13], 2)+

IntToHex (TempOut[14], 2)+IntToHex (TempOut[15], 2);

end;

Done:= Dest. Write (TempOut, SizeOf(TempOut));

st. Write (TempOut, SizeOf(TempOut));

 

Form1. MemoOut. Text:= st. DataString;

if Form1. RadioGroup1. ItemIndex = 1 then

begin

tick:= GetTickCount;

repeat

Application. ProcessMessages;

until (GetTickCount-tick)>StrToInt (Form1.editDelay. Text);

end;

if Done < SizeOf(TempOut) then

raise EStreamError. Create(SWriteError);

Dec (Count, SizeOf(TAESBuffer));

end;  if Count > 0 then

begin

Done:= Source. Read (TempIn, Count);

if Done < Count then

raise EStreamError. Create(SReadError);

FillChar (TempIn[Count], SizeOf(TempIn) –  Count, 0);

EncryptAES (TempIn, ExpandedKey, TempOut);

if flag = false then

begin

FmStop. EditIn. Text:= IntToHex (TempIn[0], 2)+IntToHex (TempIn[1], 2)+

IntToHex (TempIn[2], 2)+IntToHex (TempIn[3], 2)+IntToHex (TempIn[4], 2)+

IntToHex (TempIn[5], 2)+IntToHex (TempIn[6], 2)+IntToHex (TempIn[7], 2)+

IntToHex (TempIn[8], 2)+IntToHex (TempIn[9], 2)+IntToHex (TempIn[10], 2)+

IntToHex (TempIn[11], 2)+IntToHex (TempIn[12], 2)+IntToHex (TempIn[13], 2)+

IntToHex (TempIn[14], 2)+IntToHex (TempIn[15], 2);

 

FmStop. EditOut. Text:= IntToHex (TempOut[0], 2)+IntToHex (TempOut[1], 2)+

IntToHex (TempOut[2], 2)+IntToHex (TempOut[3], 2)+IntToHex (TempOut[4], 2)+

IntToHex (TempOut[5], 2)+IntToHex (TempOut[6], 2)+IntToHex (TempOut[7], 2)+

IntToHex (TempOut[8], 2)+IntToHex (TempOut[9], 2)+IntToHex (TempOut[10], 2)+

IntToHex (TempOut[11], 2)+IntToHex (TempOut[12], 2)+IntToHex (TempOut[13], 2)+

IntToHex (TempOut[14], 2)+IntToHex (TempOut[15], 2);

end;

Done:= Dest. Write (TempOut, SizeOf(TempOut));

st. Write (TempOut, SizeOf(TempOut));

Form1. MemoOut. Text:= st. DataString;

if Form1. RadioGroup1. ItemIndex = 0 then

begin

tick:= GetTickCount;

repeat

Application. ProcessMessages;

until (GetTickCount-tick)>StrToInt (Form1.editDelay. Text);

end;

if Done < SizeOf(TempOut) then

raise EStreamError. Create(SWriteError);

end;

st. Free;

Form1. Label_Status. Caption:= 'Шифрование завершено';

end;

procedure DecryptAESStreamECB (Source: TStream; Count: cardinal;

const Key: TAESKey128; Dest: TStream);

var

ExpandedKey: TAESExpandedKey128;

begin

ExpandAESKeyForDecryption (Key, ExpandedKey);

DecryptAESStreamECB (Source, Count, ExpandedKey, Dest);

end;

procedure DecryptAESStreamECB (Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey128; Dest: TStream);

var

tick: integer;

TempIn, TempOut: TAESBuffer;

Done: cardinal;

stt: TStringStream;

begin

stt:= TStringStream. Create('');

if Count = 0 then

begin

Source. Position:= 0;

Count:= Source. Size;

end

else Count:= Min (Count, Source. Size – Source. Position);

if Count = 0 then exit;

if (Count mod SizeOf(TAESBuffer)) > 0 then

raise EAESError. Create(SInvalidInBufSize);

while Count >= SizeOf(TAESBuffer) do

begin

Done:= Source. Read (TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError. Create(SReadError);

DecryptAES (TempIn, ExpandedKey, TempOut);

if flag = false then

begin

FmStop. EditIn. Text:= IntToHex (TempIn[0], 2)+IntToHex (TempIn[1], 2)+

IntToHex (TempIn[2], 2)+IntToHex (TempIn[3], 2)+IntToHex (TempIn[4], 2)+

IntToHex (TempIn[5], 2)+IntToHex (TempIn[6], 2)+IntToHex (TempIn[7], 2)+

IntToHex (TempIn[8], 2)+IntToHex (TempIn[9], 2)+IntToHex (TempIn[10], 2)+

IntToHex (TempIn[11], 2)+IntToHex (TempIn[12], 2)+IntToHex (TempIn[13], 2)+

IntToHex (TempIn[14], 2)+IntToHex (TempIn[15], 2);

FmStop. EditOut. Text:= IntToHex (TempOut[0], 2)+IntToHex (TempOut[1], 2)+

IntToHex (TempOut[2], 2)+IntToHex (TempOut[3], 2)+IntToHex (TempOut[4], 2)+

IntToHex (TempOut[5], 2)+IntToHex (TempOut[6], 2)+IntToHex (TempOut[7], 2)+

IntToHex (TempOut[8], 2)+IntToHex (TempOut[9], 2)+IntToHex (TempOut[10], 2)+

IntToHex (TempOut[11], 2)+IntToHex (TempOut[12], 2)+IntToHex (TempOut[13], 2)+

IntToHex (TempOut[14], 2)+IntToHex (TempOut[15], 2);

end;

stt. Write (TempOut, SizeOf(TempOut));

 

Form1. MemoOut. Text:= stt. DataString;

if Form1. RadioGroup1. ItemIndex = 1 then

begin

tick:= GetTickCount;

repeat

Application. ProcessMessages;

until (GetTickCount-tick)>StrToInt (Form1.editDelay. Text);

end;

Done:= Dest. Write (TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError. Create(SWriteError);

Dec (Count, SizeOf(TAESBuffer));

end;

stt. Free;

Form1. Label_Status. Caption:= 'Дешифрование завершено';

end;

procedure TForm1. Button1Click (Sender: TObject);

var stpath, stext: string;

begin

if OpenDialog1. Execute = True then

begin

Edit1. Text:= OpenDialog1. FileName;

MemoIn. Lines. LoadFromFile (Edit1.text);

Fpath:= Edit1. Text;

stpath:= ExtractFileDir(Fpath);

stExt:= ExtractFileExt(FPath);

If CBOpt. Text = «Шифрование» then

begin

LName. Caption:= 'Имя зашифрованого файла:';

Fpath:= stpath + '\EncodedFile'+stExt;

LPath. Caption:= FPath;

end

else

begin

LName. Caption:= 'Имя дешифрованого файла:';

 

Fpath:= stpath + '\DecodedFile'+stExt;

LPath. Caption:= FPath;

end;

end;

end;

procedure TForm1. Button2Click (Sender: TObject);

var

Source, Dest: TFileStream;

SrcFile, DestFile: string;

Start, Stop: cardinal;

Size: integer;

Key: TAESKey128;

SrcBuf, DstBuf: array [0..16383] of byte;

SrcSize, DstSize: integer;

begin

If Edit1. Text = '' then exit;

// Шифрование

if CBOpt. Text = «Шифрование» then

begin

Label_Status. Caption:= 'Шифрование…';

Refresh;

Source:= TFileStream. Create (Edit1. Text, fmOpenRead);

try

Label4. Caption:= IntToStr (Source. Size div 1024) + ' KB';

Refresh;

DestFile:= Fpath;

Dest:= TFileStream. Create (DestFile, fmCreate);  try

Size:= Source. Size;

Dest. WriteBuffer (Size, SizeOf(Size));  FillChar (Key, SizeOf(Key), 0);

Move (PChar(Edit2. Text)^, Key, Min (SizeOf(Key), Length (Edit2. Text)));

Start:= GetTickCount;

EncryptAESStreamECB (Source, 0, Key, Dest);

Stop:= GetTickCount;

Label_Time. Caption:= IntToStr (Stop – Start) + ' ms';

Refresh;

finally

Dest. Free;

end;

finally

Source. Free;

end;

end;

if CBOpt. Text = «Дешифрование» then

begin

Label_Status. Caption:= 'Дешифрование…';

Refresh;

Source:= TFileStream. Create (Edit1. Text, fmOpenRead); try

Source. ReadBuffer (Size, SizeOf(Size));

SrcFile:= fpath;

FillChar (Key, SizeOf(Key), 0);  Move (PChar(Edit2. Text)^, Key, Min (SizeOf(Key), Length (Edit2. Text)));

DestFile:= Fpath;

Dest:= TFileStream. Create (DestFile, fmCreate);

Start:= GetTickCount;

DecryptAESStreamECB (Source, Source. Size –  Source. Position, Key, Dest);

Dest. Size:= Size;

Stop:= GetTickCount;

Label_Time. Caption:= IntToStr (Stop – Start) + ' ms';

Refresh;

finally

Dest. Free;

end;

finally

Source. Free;

end;

end;

end;

procedure TForm1. ButtonStopClick (Sender: TObject);

begin

flag:= true;

FmStop. ShowModal;

repeat

Application. ProcessMessages;

until not Flag;

end;

procedure TForm1.CBOptChange (Sender: TObject);

begin

If CBOpt. Text = «Шифрование» then

begin

Button2. Caption:= 'Шифровать';

LName. Caption:= 'Имя зашифрованного файла';

end

else

begin

Button2. Caption:= 'Дешифровать';

LName. Caption:= 'Имя Дешифрованного файла';

end;

end;

procedure TForm1. FormActivate (Sender: TObject);

begin

flag:= false;

end;

procedure TForm1. RadioGroup1Click (Sender: TObject);

begin

If RadioGroup1. ItemIndex = 0 then EditDelay. Enabled:= false else

EditDelay. Enabled:= true;

end;

procedure TForm1.MFExitClick (Sender: TObject);

begin

Close;

end;

procedure TForm1.MFChooseClick (Sender: TObject);

begin

Button1. Click;

end;

procedure TForm1. FormCreate (Sender: TObject);

begin

Application. HelpFile:= GetCurrentDir +'\AES.hlp';

end;

procedure TForm1.MHHelpClick (Sender: TObject);

begin

Application. HelpCommand (HELP_CONTENTS, 1);

end;

end.

 

 


Информация о работе Розробка програми „ Криптоаналiз ”