-
Notifications
You must be signed in to change notification settings - Fork 1
/
AES-Encryption.asm
102 lines (97 loc) · 2.03 KB
/
AES-Encryption.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
; Assembly with nasm -f elf AES-Encryption.asm
; Link with ld -m elf_i386 AES-Encryption.o -o AES-Encryption
; Or just run make like a chad
%include "IO.inc" ; Custom Written IO library
%include "Encryption.inc" ; Encryption functions
%include "Decryption.inc" ; Decryption functions
%include "Socket.inc" ; Socket functions
global _start
section .data
message TIMES 16 db 0
key TIMES 16 db 0
PromptMessage db "Enter the message: ",0
PromptHex db "Enter the 16 hex bytes as lowercase without leading '0x', pad the bytes to be 2 digits wide:", 0xA
PromptKey db "Enter the key: ", 0
PromptDec db "1.Encrypt", 0xA, "2.Decrypt", 0xA
section .text
_start:
cmp DWORD [esp], 1
ja .server
;Ask whether to encrypt or decrypt
mov esi, PromptDec
mov ecx, 20
call WriteString
call ReadChar
cmp al, 0x31
jne .decrypt
;Print prompt for message
mov esi, PromptMessage
mov ecx, 20
call WriteString
;Read message
mov esi, message
mov ecx, 18
call ReadString
;Print prompt for key
mov esi, PromptKey
mov ecx, 15
call WriteString
;Read key
mov esi, key
mov ecx, 17
call ReadString
;Encrypt the message
mov esi, message
mov edi, key
call Encrypt
;Print the encrypted message
mov esi, message
call Print4x4Matrix
jmp .done
.decrypt:
;Print promp for encrypted message
mov esi, PromptHex
mov ecx, 93
call WriteString
;Read 16 bytes
mov esi, message
mov ecx, 16
.input:
call ReadHexByte
mov BYTE[esi], al
inc esi
loop .input
;Print prompt for key
mov esi, PromptKey
mov ecx, 15
call WriteString
;Read key
mov esi, key
mov ecx, 17
call ReadString
;Decrypt the string
mov esi, message
mov edi, key
call Decrypt
;Print decrypted string
mov esi, message
mov ecx, 16
call WriteString
jmp .done
.server:
mov eax, [esp+8]
call SetSocketFromArg
mov esi, prompt
mov ecx, 30
call WriteString
mov bx, [socket]
xchg bl, bh
movzx eax, bx
call WriteDec
call WriteLine
call InitialiseServer
.done:
;Return zero
mov eax, 0x1
mov ebx, 0
int 0x80