-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenigma.asm
130 lines (109 loc) · 2.87 KB
/
enigma.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
;****************************************
;* Tecnológico de Costa Rica *
;* Ingeniería en Computación *
;* Arquitectura de Computadoras *
;* Profe: *
;* Erick Hernández Bonilla *
;* Proyecto: *
;* Máquina Enigma en Ensamblador *
;* Alumnos: *
;* Melissa Molina 2013006074 *
;* Liza Chaves Carranza 2013016573 *
;* Fabián Monge *
;* Gabreiel Pizarro 201216833 *
;****************************************
%include "string.mac"
%include "cifrado.mac"
section .bss
bufTmp: resb 1024
bufTextTmp: resb 1024
textIn: resb 1024
lenTextIn: equ $ - textIn
textoCifrado: resb 1024
lenTextoCifrado: equ $ - textoCifrado
;plugboard: resb 29
;lenPlugboard: equ $ - plugboard
; ejemplo de blugboard:
; XF,PZ,SQ,GR,AJ,UO,CN,BV,TM,KI
section .data
newline: db 0x0A
;rotorUno: db 'EKMFLGDQVZNTOWYHXUSPAIBRCJ'
;rotorDos: db 'AJDKSIRUXBLHWTMCQGZNPYFVOE'
;rotorTres: db 'BDFHJLCPRTXVZNYEIWGAKMUSQO'
;rotorTres: db 'AXYDEBCVQJKFGLMRHINOPUWSTZ'
;rotorDos: db 'PTOSMXUWEBVQFACJDIGLKZNYRH'
;rotorUno: db 'ZPTWYLOUESMBXVQNFADIGCJKRH'
;;;;; ABCDEFGHIJKLMNOPQRSTUVWXYZ
plugboard: db 'XF,PZ,SQ,GR,AJ,UO,CN,BV,TM,KI'
lenRotores: equ $ - rotorUno
rotorI: db 'EKMFLGDQVZNTOWYHXUSPAIBRCJ'
rotorII: db 'AJDKSIRUXBLHWTMCQGZNPYFVOE'
rotorIII: db 'BDFHJLCPRTXVZNYEIWGAKMUSQO'
rotorIV: db 'ESOVPZJAYQUIRHXLNFTGKDCMWB'
rotorV: db 'VZBRGITYUPSDNHLXAWMJQOFECK'
reflector: db 'EJMZALYXVBWFCRQUONTSPIKHGD'
;reflector: db 'YAMQRXSUJGZWVCTHLIPFOBNKED'
;reflectorB: db 'YRUHQSLDPXNGOKMIEBFZCWVJAT'
;reflectorC: db 'FVPJIAOYEDRZXWGCTKUQSBNMHL'
;estatico: db 'ABCDEFHGIJKLMNOPQRSTUVWXYZ'
;plugboard: resb 29
;lenPlugboard: equ $ - plugboard
; ejemplo de blugboard:
;XF,PZ,SQ,GR,AJ,UO,CN,BV,TM,Ki
section .text
global _start
_start:
xor rdi, rdi
xor rdx, rdx
xor rax, rax
xor rbx, rbx
leer textIn, lenTextIn ;len de lectura --> rax
mov rcx, rax
dec rcx ;quitar 0x0A
xor r8, r8
mov r8, rcx
dec r8
mov r10, rax
; xor r10, r10
rotarBufIzq rotorUno, 4
rotarBufIzq rotorDos, 4
rotarBufIzq rotorTres, 4
; movBuf bufTextTmp, textIn ; mov textX, textY
; movBuf textoCifrado, textIn
;; call copiarBuf
xor r15, r15
xor r13, r13
dec r15
.loop:
inc r15
mov al, byte[textIn+r15]
mov [textoCifrado], al
plugboardM 1, plugboard ;XF,PZ,SQ,GR,AJ,UO,CN,BV,TM,Ki
call printText ;call rotores ;rbx ==> puntero-cont recorre el bufer
rotoresM rotorUno, 1
call printText
rotoresM rotorDos, 2
call printText
rotoresM rotorTres, 3
call printText
rotoresM reflector, 0
call printText
rotoresOutM rotorTres, 3, r15
call printText
rotoresOutM rotorDos, 2, r15
call printText
rotoresOutM rotorUno, 1, r15
call printText
plugboardM lenTextIn, plugboard
call printText
print newline, 1
cmp r15, r8
jne .loop
exit
printText:
print newline, 1
print textoCifrado, lenTextIn
lea rsi, [textIn]
lea rdi, [textoCifrado]
ret
;end prinf