Розробка програми „ Криптоанал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 Кб (Скачать файл)

$C74E4987, $C1D138D9, $FEA2CA8C, $360BD498, $CF81F5A6, $28DE7AA5, $268EB7DA, $A4BFAD3F,

$E49D3A2C, $0D927850, $9BCC5F6A, $62467E54, $C2138DF6, $E8B8D890, $5EF7392E, $F5AFC382,

$BE805D9F, $7C93D069, $A92DD56F, $B31225CF, $3B99ACC8, $A77D1810, $6E639CE8, $7BBB3BDB,

$097826CD, $F418596E, $01B79AEC, $A89A4F83, $656E95E6, $7EE6FFAA, $08CFBC21, $E6E815EF,

$D99BE7BA, $CE366F4A, $D4099FEA, $D67CB029, $AFB2A431, $31233F2A, $3094A5C6, $C066A235,

$37BC4E74, $A6CA82FC, $B0D090E0, $15D8A733, $4A9804F1, $F7DAEC41, $0E50CD7F, $2FF69117,

$8DD64D76, $4DB0EF43, $544DAACC, $DF0496E4, $E3B5D19E, $1B886A4C, $B81F2CC1, $7F516546,

$04EA5E9D, $5D358C01, $737487FA, $2E410BFB, $5A1D67B3, $52D2DB92, $335610E9, $1347D66D,

$8C61D79A, $7A0CA137, $8E14F859, $893C13EB, $EE27A9CE, $35C961B7, $EDE51CE1, $3CB1477A,

$59DFD29C, $3F73F255, $79CE1418, $BF37C773, $EACDF753, $5BAAFD5F, $146F3DDF, $86DB4478,

$81F3AFCA, $3EC468B9, $2C342438, $5F40A3C2, $72C31D16, $0C25E2BC, $8B493C28, $41950DFF,

$7101A839, $DEB30C08, $9CE4B4D8, $90C15664, $6184CB7B, $70B632D5, $745C6C48, $4257B8D0

);

 

LastInverseTable: array [0..255] of longword = (

$00000052, $00000009, $0000006A, $000000D5, $00000030, $00000036, $000000A5, $00000038,

$000000BF, $00000040, $000000A3, $0000009E, $00000081, $000000F3, $000000D7, $000000FB,

$0000007C, $000000E3, $00000039, $00000082, $0000009B, $0000002F, $000000FF, $00000087,

$00000034, $0000008E, $00000043, $00000044, $000000C4, $000000DE, $000000E9, $000000CB,

$00000054, $0000007B, $00000094, $00000032, $000000A6, $000000C2, $00000023, $0000003D,

$000000EE, $0000004C, $00000095, $0000000B, $00000042, $000000FA, $000000C3, $0000004E,

$00000008, $0000002E, $000000A1, $00000066, $00000028, $000000D9, $00000024, $000000B2,

$00000076, $0000005B, $000000A2, $00000049, $0000006D, $0000008B, $000000D1, $00000025,

$00000072, $000000F8, $000000F6, $00000064, $00000086, $00000068, $00000098, $00000016,

$000000D4, $000000A4, $0000005C, $000000CC, $0000005D, $00000065, $000000B6, $00000092,

$0000006C, $00000070, $00000048, $00000050, $000000FD, $000000ED, $000000B9, $000000DA,

$0000005E, $00000015, $00000046, $00000057, $000000A7, $0000008D, $0000009D, $00000084,

$00000090, $000000D8, $000000AB, $00000000, $0000008C, $000000BC, $000000D3, $0000000A,

$000000F7, $000000E4, $00000058, $00000005, $000000B8, $000000B3, $00000045, $00000006,

$000000D0, $0000002C, $0000001E, $0000008F, $000000CA, $0000003F, $0000000F, $00000002,

$000000C1, $000000AF, $000000BD, $00000003, $00000001, $00000013, $0000008A, $0000006B,

$0000003A, $00000091, $00000011, $00000041, $0000004F, $00000067, $000000DC, $000000EA,

$00000097, $000000F2, $000000CF, $000000CE, $000000F0, $000000B4, $000000E6, $00000073,

$00000096, $000000AC, $00000074, $00000022, $000000E7, $000000AD, $00000035, $00000085,

$000000E2, $000000F9, $00000037, $000000E8, $0000001C, $00000075, $000000DF, $0000006E,

$00000047, $000000F1, $0000001A, $00000071, $0000001D, $00000029, $000000C5, $00000089,

$0000006F, $000000B7, $00000062, $0000000E, $000000AA, $00000018, $000000BE, $0000001B,

$000000FC, $00000056, $0000003E, $0000004B, $000000C6, $000000D2, $00000079, $00000020,

$0000009A, $000000DB, $000000C0, $000000FE, $00000078, $000000CD, $0000005A, $000000F4,

$0000001F, $000000DD, $000000A8, $00000033, $00000088, $00000007, $000000C7, $00000031,

$000000B1, $00000012, $00000010, $00000059, $00000027, $00000080, $000000EC, $0000005F,

$00000060, $00000051, $0000007F, $000000A9, $00000019, $000000B5, $0000004A, $0000000D,

$0000002D, $000000E5, $0000007A, $0000009F, $00000093, $000000C9, $0000009C, $000000EF,

$000000A0, $000000E0, $0000003B, $0000004D, $000000AE, $0000002A, $000000F5, $000000B0,

$000000C8, $000000EB, $000000BB, $0000003C, $00000083, $00000053, $00000099, $00000061,

$00000017, $0000002B, $00000004, $0000007E, $000000BA, $00000077, $000000D6, $00000026,

$000000E1, $00000069, $00000014, $00000063, $00000055, $00000021, $0000000C, $0000007D

);

procedure ExpandAESKeyForEncryption (const Key: TAESKey128; var ExpandedKey: TAESExpandedKey128);

var

I, J: integer;

T: longword;

W0, W1, W2, W3: longword;

begin

ExpandedKey[0]:= PLongWord (@Key[0])^;

ExpandedKey[1]:= PLongWord (@Key[4])^;

ExpandedKey[2]:= PLongWord (@Key[8])^;

ExpandedKey[3]:= PLongWord (@Key[12])^;

I:= 0; J:= 1;

repeat

T:= (ExpandedKey [I + 3] shl 24) or (ExpandedKey [I + 3] shr 8);

W0:= LastForwardTable [Byte(T)]; W1:= LastForwardTable [Byte(T shr 8)];

W2:= LastForwardTable [Byte(T shr 16)]; W3:= LastForwardTable [Byte(T shr 24)];

ExpandedKey [I + 4]:= ExpandedKey[I] xor

(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 Rcon[J];

Inc(J);

ExpandedKey [I + 5]:= ExpandedKey [I + 1] xor ExpandedKey [I + 4];

ExpandedKey [I + 6]:= ExpandedKey [I + 2] xor ExpandedKey [I + 5];

ExpandedKey [I + 7]:= ExpandedKey [I + 3] xor ExpandedKey [I + 6];

Inc (I, 4);

until I >= 40;

end;

procedure EncryptAES (const InBuf: TAESBuffer; const Key: TAESExpandedKey128;

var OutBuf: TAESBuffer);

var

T0, T1: array [0..3] of longword;

W0, W1, W2, W3: longword;

begin

 

T0 [0]:= PLongWord (@InBuf[0])^ xor Key[0];

T0 [1]:= PLongWord (@InBuf[4])^ xor Key[1];

T0 [2]:= PLongWord (@InBuf[8])^ xor Key[2];

T0 [3]:= PLongWord (@InBuf[12])^ xor Key[3];

 

 

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

W2:= ForwardTable [Byte(T0 [2] shr 16)]; W3:= ForwardTable [Byte(T0 [3] 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:= ForwardTable [Byte(T0 [1])]; W1:= ForwardTable [Byte(T0 [2] shr 8)];

W2:= ForwardTable [Byte(T0 [3] shr 16)]; W3:= ForwardTable [Byte(T0 [0] 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:= ForwardTable [Byte(T0 [2])]; W1:= ForwardTable [Byte(T0 [3] shr 8)];

W2:= ForwardTable [Byte(T0 [0] shr 16)]; W3:= ForwardTable [Byte(T0 [1] 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:= ForwardTable [Byte(T0 [3])]; W1:= ForwardTable [Byte(T0 [0] shr 8)];

W2:= ForwardTable [Byte(T0 [1] shr 16)]; W3:= ForwardTable [Byte(T0 [2] 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:= ForwardTable [Byte(T1 [0])]; W1:= ForwardTable [Byte(T1 [1] shr 8)];

W2:= ForwardTable [Byte(T1 [2] shr 16)]; W3:= ForwardTable [Byte(T1 [3] 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:= ForwardTable [Byte(T1 [1])]; W1:= ForwardTable [Byte(T1 [2] shr 8)];

W2:= ForwardTable [Byte(T1 [3] shr 16)]; W3:= ForwardTable [Byte(T1 [0] 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:= ForwardTable [Byte(T1 [2])]; W1:= ForwardTable [Byte(T1 [3] shr 8)];

W2:= ForwardTable [Byte(T1 [0] shr 16)]; W3:= ForwardTable [Byte(T1 [1] 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:= ForwardTable [Byte(T1 [3])]; W1:= ForwardTable [Byte(T1 [0] shr 8)];

W2:= ForwardTable [Byte(T1 [1] shr 16)]; W3:= ForwardTable [Byte(T1 [2] 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:= ForwardTable [Byte(T0 [0])]; W1:= ForwardTable [Byte(T0 [1] shr 8)];

W2:= ForwardTable [Byte(T0 [2] shr 16)]; W3:= ForwardTable [Byte(T0 [3] 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:= ForwardTable [Byte(T0 [1])]; W1:= ForwardTable [Byte(T0 [2] shr 8)];

W2:= ForwardTable [Byte(T0 [3] shr 16)]; W3:= ForwardTable [Byte(T0 [0] 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:= ForwardTable [Byte(T0 [2])]; W1:= ForwardTable [Byte(T0 [3] shr 8)];

W2:= ForwardTable [Byte(T0 [0] shr 16)]; W3:= ForwardTable [Byte(T0 [1] 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:= ForwardTable [Byte(T0 [3])]; W1:= ForwardTable [Byte(T0 [0] shr 8)];

W2:= ForwardTable [Byte(T0 [1] shr 16)]; W3:= ForwardTable [Byte(T0 [2] 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:= ForwardTable [Byte(T1 [0])]; W1:= ForwardTable [Byte(T1 [1] shr 8)];

W2:= ForwardTable [Byte(T1 [2] shr 16)]; W3:= ForwardTable [Byte(T1 [3] 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:= ForwardTable [Byte(T1 [1])]; W1:= ForwardTable [Byte(T1 [2] shr 8)];

W2:= ForwardTable [Byte(T1 [3] shr 16)]; W3:= ForwardTable [Byte(T1 [0] 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:= ForwardTable [Byte(T1 [2])]; W1:= ForwardTable [Byte(T1 [3] shr 8)];

W2:= ForwardTable [Byte(T1 [0] shr 16)]; W3:= ForwardTable [Byte(T1 [1] 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:= ForwardTable [Byte(T1 [3])]; W1:= ForwardTable [Byte(T1 [0] shr 8)];

W2:= ForwardTable [Byte(T1 [1] shr 16)]; W3:= ForwardTable [Byte(T1 [2] 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:= ForwardTable [Byte(T0 [0])]; W1:= ForwardTable [Byte(T0 [1] shr 8)];

W2:= ForwardTable [Byte(T0 [2] shr 16)]; W3:= ForwardTable [Byte(T0 [3] 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:= ForwardTable [Byte(T0 [1])]; W1:= ForwardTable [Byte(T0 [2] shr 8)];

W2:= ForwardTable [Byte(T0 [3] shr 16)]; W3:= ForwardTable [Byte(T0 [0] 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:= ForwardTable [Byte(T0 [2])]; W1:= ForwardTable [Byte(T0 [3] shr 8)];

W2:= ForwardTable [Byte(T0 [0] shr 16)]; W3:= ForwardTable [Byte(T0 [1] 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:= ForwardTable [Byte(T0 [3])]; W1:= ForwardTable [Byte(T0 [0] shr 8)];

W2:= ForwardTable [Byte(T0 [1] shr 16)]; W3:= ForwardTable [Byte(T0 [2] 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:= ForwardTable [Byte(T1 [0])]; W1:= ForwardTable [Byte(T1 [1] shr 8)];

W2:= ForwardTable [Byte(T1 [2] shr 16)]; W3:= ForwardTable [Byte(T1 [3] 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:= ForwardTable [Byte(T1 [1])]; W1:= ForwardTable [Byte(T1 [2] shr 8)];

W2:= ForwardTable [Byte(T1 [3] shr 16)]; W3:= ForwardTable [Byte(T1 [0] 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:= ForwardTable [Byte(T1 [2])]; W1:= ForwardTable [Byte(T1 [3] shr 8)];

W2:= ForwardTable [Byte(T1 [0] shr 16)]; W3:= ForwardTable [Byte(T1 [1] 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:= ForwardTable [Byte(T1 [3])]; W1:= ForwardTable [Byte(T1 [0] shr 8)];

W2:= ForwardTable [Byte(T1 [1] shr 16)]; W3:= ForwardTable [Byte(T1 [2] 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:= ForwardTable [Byte(T0 [0])]; W1:= ForwardTable [Byte(T0 [1] shr 8)];

W2:= ForwardTable [Byte(T0 [2] shr 16)]; W3:= ForwardTable [Byte(T0 [3] 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[28];

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

W2:= ForwardTable [Byte(T0 [3] shr 16)]; W3:= ForwardTable [Byte(T0 [0] 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[29];

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

W2:= ForwardTable [Byte(T0 [0] shr 16)]; W3:= ForwardTable [Byte(T0 [1] 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:= ForwardTable [Byte(T0 [3])]; W1:= ForwardTable [Byte(T0 [0] shr 8)];

W2:= ForwardTable [Byte(T0 [1] shr 16)]; W3:= ForwardTable [Byte(T0 [2] 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:= ForwardTable [Byte(T1 [0])]; W1:= ForwardTable [Byte(T1 [1] shr 8)];

W2:= ForwardTable [Byte(T1 [2] shr 16)]; W3:= ForwardTable [Byte(T1 [3] 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[32];

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

W2:= ForwardTable [Byte(T1 [3] shr 16)]; W3:= ForwardTable [Byte(T1 [0] 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[33];

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

W2:= ForwardTable [Byte(T1 [0] shr 16)]; W3:= ForwardTable [Byte(T1 [1] 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[34];

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

W2:= ForwardTable [Byte(T1 [1] shr 16)]; W3:= ForwardTable [Byte(T1 [2] 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[35];

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

W2:= ForwardTable [Byte(T0 [2] shr 16)]; W3:= ForwardTable [Byte(T0 [3] 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[36];

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

W2:= ForwardTable [Byte(T0 [3] shr 16)]; W3:= ForwardTable [Byte(T0 [0] 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[37];

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

W2:= ForwardTable [Byte(T0 [0] shr 16)]; W3:= ForwardTable [Byte(T0 [1] 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[38];

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

W2:= ForwardTable [Byte(T0 [1] shr 16)]; W3:= ForwardTable [Byte(T0 [2] 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[39];

 

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

W2:= LastForwardTable [Byte(T1 [2] shr 16)]; W3:= LastForwardTable [Byte(T1 [3] 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[40];

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

W2:= LastForwardTable [Byte(T1 [3] shr 16)]; W3:= LastForwardTable [Byte(T1 [0] 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[41];

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

W2:= LastForwardTable [Byte(T1 [0] shr 16)]; W3:= LastForwardTable [Byte(T1 [1] 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[42];

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

W2:= LastForwardTable [Byte(T1 [1] shr 16)]; W3:= LastForwardTable [Byte(T1 [2] 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[43];

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

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

end;

procedure ExpandAESKeyForDecryption (var ExpandedKey: TAESExpandedKey128);

var

I: integer;

U, F2, F4, F8, F9: longword;

begin

for I:= 1 to 9 do

begin

 

F9:= ExpandedKey [I * 4];

U:= F9 and $80808080;

F2:= ((F9 and $7F7F7F7F) shl 1) xor ((U –  (U shr 7)) and $1B1B1B1B);

U:= F2 and $80808080;

F4:= ((F2 and $7F7F7F7F) shl 1) xor ((U –  (U shr 7)) and $1B1B1B1B);

U:= F4 and $80808080;

F8:= ((F4 and $7F7F7F7F) shl 1) xor ((U –  (U shr 7)) and $1B1B1B1B);

F9:= F9 xor F8;

ExpandedKey [I * 4]:= F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

F9:= ExpandedKey [I * 4 + 1];

U:= F9 and $80808080;

F2:= ((F9 and $7F7F7F7F) shl 1) xor ((U –  (U shr 7)) and $1B1B1B1B);

U:= F2 and $80808080;

F4:= ((F2 and $7F7F7F7F) shl 1) xor ((U –  (U shr 7)) and $1B1B1B1B);

U:= F4 and $80808080;

F8:= ((F4 and $7F7F7F7F) shl 1) xor ((U –  (U shr 7)) and $1B1B1B1B);

F9:= F9 xor F8;

ExpandedKey [I * 4 + 1]:= F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

F9:= ExpandedKey [I * 4 + 2];

U:= F9 and $80808080;

F2:= ((F9 and $7F7F7F7F) shl 1) xor ((U –  (U shr 7)) and $1B1B1B1B);

U:= F2 and $80808080;

F4:= ((F2 and $7F7F7F7F) shl 1) xor ((U –  (U shr 7)) and $1B1B1B1B);

U:= F4 and $80808080;

F8:= ((F4 and $7F7F7F7F) shl 1) xor ((U –  (U shr 7)) and $1B1B1B1B);

F9:= F9 xor F8;

ExpandedKey [I * 4 + 2]:= F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

F9:= ExpandedKey [I * 4 + 3];

U:= F9 and $80808080;

F2:= ((F9 and $7F7F7F7F) shl 1) xor ((U –  (U shr 7)) and $1B1B1B1B);

U:= F2 and $80808080;

F4:= ((F2 and $7F7F7F7F) shl 1) xor ((U –  (U shr 7)) and $1B1B1B1B);

U:= F4 and $80808080;

F8:= ((F4 and $7F7F7F7F) shl 1) xor ((U –  (U shr 7)) and $1B1B1B1B);

F9:= F9 xor F8;

ExpandedKey [I * 4 + 3]:= F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

end;

end;

procedure ExpandAESKeyForDecryption (const Key: TAESKey128; var ExpandedKey: TAESExpandedKey128);

begin

ExpandAESKeyForEncryption (Key, ExpandedKey);

 

ExpandAESKeyForDecryption(ExpandedKey);

end;

procedure DecryptAES (const InBuf: TAESBuffer; const Key: TAESExpandedKey128;

var OutBuf: TAESBuffer);

var

T0, T1: array [0..3] of longword;

W0, W1, W2, W3: longword;

begin

 

T0 [0]:= PLongWord (@InBuf[0])^ xor Key[40];

T0 [1]:= PLongWord (@InBuf[4])^ xor Key[41];

T0 [2]:= PLongWord (@InBuf[8])^ xor Key[42];

T0 [3]:= PLongWord (@InBuf[12])^ xor Key[43];

 

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[36];

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[37];

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[38];

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[39];

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[32];

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[33];

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[34];

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[35];

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[28];

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[29];

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

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