-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt_subrotine.asm
87 lines (55 loc) · 1.2 KB
/
encrypt_subrotine.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
; 8086 subroutine to encrypt/decrypt lower case characters using xlat
name "crypt"
org 100h
jmp start
; string has '$' in the end:
string1 db 'hello world!', 0Dh,0Ah, '$'
; 'abcdefghijklmnopqrstvuwxyz'
table1 db 97 dup (' '), 'klmnxyzabcopqrstvuwdefghij'
table2 db 97 dup (' '), 'hijtuvwxyzabcdklmnoprqsefg'
start:
; encrypt:
lea bx, table1
lea si, string1
call parse
; show result:
lea dx, string1
; output of a string at ds:dx
mov ah, 09
int 21h
; decrypt:
lea bx, table2
lea si, string1
call parse
; show result:
lea dx, string1
; output of a string at ds:dx
mov ah, 09
int 21h
; wait for any key...
mov ah, 0
int 16h
ret ; exit to operating system.
; subroutine to encrypt/decrypt
; parameters:
; si - address of string to encrypt
; bx - table to use.
parse proc near
next_char:
cmp [si], '$' ; end of string?
je end_of_string
mov al, [si]
cmp al, 'a'
jb skip
cmp al, 'z'
ja skip
; xlat algorithm: al = ds:[bx + unsigned al]
xlatb ; encrypt using table2.
mov [si], al
skip:
inc si
jmp next_char
end_of_string:
ret
parse endp
end