-
Notifications
You must be signed in to change notification settings - Fork 0
/
vigenere.asm
109 lines (103 loc) · 2.22 KB
/
vigenere.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
103
104
105
106
107
108
109
%include "io.mac"
section .bss
plaintext_len: resd 1
key_len: resd 1
aux_ecx: resd 1
section .text
global vigenere
extern printf
vigenere:
;; DO NOT MODIFY
push ebp
mov ebp, esp
pusha
mov edx, [ebp + 8] ; ciphertext
mov esi, [ebp + 12] ; plaintext
mov ecx, [ebp + 16] ; plaintext_len
mov edi, [ebp + 20] ; key
mov ebx, [ebp + 24] ; key_len
;; DO NOT MODIFY
;; TODO: Implement the Vigenere cipher
; retinere valori pentru a putea folosi registrele
mov [plaintext_len], ecx
mov [key_len], ebx
xor ecx, ecx
xor eax, eax
xor ebx, ebx
;; inceput while
;; se parcurge sirul caracter cu caracter si se realizeaza criptarea
start:
xor eax, eax
cmp ebx, [key_len] ;; pozitia in key
jge actualizare_ebx
back:
xor eax, eax
mov [aux_ecx], ecx ; retinere o copie a lui ecx
mov al, byte[esi + ecx] ; extragere caracter din plaintext
mov cl, byte[edi + ebx] ; extragere caracter din key
; verificare daca este litera caracterul extras din plaintext
cmp al, 'A'
jl non_char
cmp al, 'Z'
jle found
cmp al, 'a'
jl non_char
cmp al, 'z'
jg non_char
; gasit litera mica
; prelucrarea caracterului si introducerea lui in cyphertext
; asemanator cu caesar
sub cl, 'A'
add eax, ecx
cmp eax, 'z'
jg rotate_lower
mov ecx, dword[aux_ecx]
mov byte[edx + ecx], al
jmp end
found: ; gasit litera mare
; prelucrarea caracterului si introducerea lui in cyphertext
; asemanator cu caesar
sub cl, 'A'
add eax, ecx
cmp eax, 'Z'
jg rotate_upper
mov ecx, dword[aux_ecx]
mov byte[edx + ecx], al
jmp end
rotate_lower:
sub al, 'z'
dec al
add al, 'a'
cmp al, 'z'
jg rotate_lower
mov ecx, dword[aux_ecx]
mov byte[edx + ecx], al
jmp end
rotate_upper:
sub al, 'Z'
dec al
add al, 'A'
cmp al, 'Z'
jg rotate_upper
mov ecx, dword[aux_ecx]
mov byte[edx + ecx], al
jmp end
non_char:
mov ecx, dword[aux_ecx]
mov byte[edx + ecx], al
jmp end_2
end:
inc ebx
end_2:
inc ecx
cmp ecx, [plaintext_len]
jle start
;; End Vigenere Cipher
;; DO NOT MODIFY
popa
leave
ret
actualizare_ebx: ;; cand se depaseste lungimea key-ului
xor ebx, ebx
jmp back
;; DO NOT MODIFY