-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.asm
150 lines (117 loc) · 2.39 KB
/
Main.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
.486
%TITLE "Passwords Maneger"
IDEAL
MODEL small
MACRO SHOW_MSG MSG
mov dx, offset MSG
mov ah,9
int 21h
ENDM SHOW_MSG
MACRO Getch
mov ah, 1
int 21h
ENDM Getch
MACRO GetDigit
Getch
sub al, '0' ;30h - to convert from ascii to digit
ENDM GetDigit
MACRO WaitKey
mov ah, 7
int 21h
ENDM WaitKey
MACRO NEW_LINE
mov dl,13 ; CR = Caridge Return - go to row start position
mov ah,2
int 21h
mov dl,10 ; LF = Line Feed - go down to the next line
int 21h
ENDM NEW_LINE
MACRO ClearScr
xor ah, ah
mov al, 3
int 10h
ENDM ClearScr
STACK 100h
include "Main.inc"
DATASEG
Base32EnterStart db "Please put ", '$'
Base32EnterCont db " as the secret key in your TOTP app", 10, 13, '$'
EnterCode db "Please enter the 6-digit code that you got from the TOTP app: ", '$'
WrongCode db "Wrong code, please try again ", 10, 13, '$'
SuccessMSG db "Congrats, you're in", 10, 13, '$'
PressToContMSG db "Press any key to continue . . . ", '$'
CODESEG
start:
mov ax, @data
mov ds, ax
call Main
EXIT:
mov ax, 4c00h
int 21h
;---------------------------
; Procudures area
;---------------------------
proc Main
call MainTOTP
call ManageAll
ret
endp Main
;Manages TOTP input and authentication
proc MainTOTP
@@ProcStart:
ClearScr
SHOW_MSG Base32EnterStart
call PrintBase32
SHOW_MSG Base32EnterCont
SHOW_MSG PressToContMSG
WaitKey
ClearScr
SHOW_MSG EnterCode
call GetSixDigitCode
call GoogleAuthenticator
cmp cx, dx
jne @@TryAgain
@@CheckLowOrder:
cmp bx, ax
jne @@TryAgain
;if we got here the code is correct
NEW_LINE
SHOW_MSG SuccessMSG
ret
@@TryAgain:
NEW_LINE
SHOW_MSG WrongCode ;jne --> wrong
SHOW_MSG PressToContMSG
WaitKey
jmp @@ProcStart
endp MainTOTP
proc GetSixDigitCode ;Gets the 6 digit code from the user. Output goes to cx:bx
xor cx, cx
xor bx, bx
mov ax, 50000
mov si, 5
@@GetLoop:
push ax
GetDigit
xor ah, ah
mov di, ax
pop ax
push ax
mul di ; dx:ax = 5* (10^n) * digit
shl ax, 1
rcl dx, 1 ;32bit shift left (to multiply by 2) --> x*5*2 = x*10
add bx, ax
adc cx, dx
pop ax
xor dx, dx
mov di, 10
div di ;div ax by 10
dec si
jnz @@GetLoop
GetDigit
xor ah, ah
add bx, ax
adc cx, 0
ret
endp GetSixDigitCode
END start