-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolumnar.asm
68 lines (64 loc) · 2.68 KB
/
columnar.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
section .data
extern len_cheie, len_haystack
section .text
global columnar_transposition
;; void columnar_transposition(int key[], char *haystack, char *ciphertext);
columnar_transposition:
;; DO NOT MODIFY
push ebp
mov ebp, esp
pusha
mov edi, [ebp + 8] ; key
mov esi, [ebp + 12] ; haystack
mov ebx, [ebp + 16] ; ciphertext
;; DO NOT MODIFY
;; TODO: Implment columnar_transposition
;; FREESTYLE STARTS HERE
xor ecx, ecx ; ecx=i=0
xor eax, eax ; eax=j=0
xor edx, edx ; edx=k=0
through_key:
cmp ecx, [len_cheie] ; daca i>=len_cheie
jge the_end ; sfarsit
through_haystack:
cmp eax, [len_haystack] ; altfel, daca j>=len_haystack
jge go_to_next_key ; i++, j=0, inapoi la through_key (for)
push ebx ; salvez ebx pe stiva
push edx ; salvez edx pe stiva
push eax ; salvez eax pe stiva
xor edx, edx ; edx=0
mov ebx, [len_cheie] ; ebx=len_cheie
div ebx ; eax=j/len_cheie; edx=j%len_cheie;
pop eax ; eax=j
cmp edx, [edi + ecx*4] ; daca j%len_cheie==key[i]
je put_char_in_ciphertext ; mergi la put_char_in_ciphertext
pop edx ; scot edx de pe stiva: edx=k
pop ebx ; scot ebx de pe stiva: ebx=ciphertext
go_to_next_char:
inc eax ; j++
jmp through_haystack ; inapoi la through_haystack (for)
go_to_next_key:
inc ecx ; i++
xor eax, eax ; j=0
jmp through_key ; inapoi la through_key (for)
put_char_in_ciphertext:
pop edx ; scot edx de pe stiva: edx=k
pop ebx ; scot ebx de pe stiva: ebx=ciphertext
push ecx ; salvex ecx pe stiva
mov cl, [esi + eax] ; cl=haystack[j]
mov [ebx + edx], cl ; ciphertext[k]=haystack[j]
pop ecx ; scot ecx de pe stiva: ecx=i
inc edx ; k++
cmp edx, [len_haystack] ; daca k==len_haystack
je end_haystack ; ciphertext[k]='\0'
jmp go_to_next_char ; inapoi la go_to_next_char (for)
end_haystack:
mov byte [ebx + edx], 0 ; ciphertext[k]='\0'
jmp go_to_next_char ; inapoi la go_to_next_char (for)
the_end:
;; FREESTYLE ENDS HERE
;; DO NOT MODIFY
popa
leave
ret
;; DO NOT MODIFY