汇编语言程序设计-字符串加密解密

2010-05-09 16:00

;加密解密的实现

;输入1,自动换行后输入要加密的字符串,回车显示加密后的字符串

;输入其他任意键值,自动换行后输入要解密的字符串,回车显示原文

;这是微机原理软件实验一个小题目,我采用的最简单加密算法,即对原字符加一

;解密时对密文减一,实验时,加密解密可采用替换算法

;没有将输出回车换行做成子程序,以至于程序比较长

;加密原文并输出

  1 sseg segment stack
2 db 100h dup(?)
3 sseg ends
4
5 dseg segment byte
6 tip db 'press 1 to change the words' ,0dh,0ah,'press other key to rechange the words',0dh,0ah,'$'
7 msg db 50 dup(?)
8 dst db 50 dup(?)
9 dseg ends
10
11 cseg segment
12 ;..........................................
13 main proc far
14 assume cs:cseg,ds:dseg
15 start:
16 mov ax, dseg
17 mov ds, ax
18 mov dx, offset tip
19 mov ah, 09h
20
21 int 21h
22 mov ah,1
23 int 21h
24 mov bl,al
25
26 mov dl,13
27 mov ah,2
28 int 21h
29 mov dl,10
30 mov al,2
31 int 21h
32
33 cmp bl,31h
34 jne labl
35 call input
36 call change
37 call print
38 jmp exit
39 labl:
40 call input
41 call rechange
42 call print
43 exit:
44 mov ah, 4Ch
45 int 21h
46 main endp
47 ;...........................................
48 change proc near
49 push ax
50 push cx
51 push si
52 push di
53 mov ax, dseg
54 mov ds, ax
55 lea si,msg
56 lea di,dst
57 again1:
58 mov ax,[si]
59 cmp ax,24h
60 je exit1
61 mov cx,ax
62 add cx,1
63 mov [di],cx
64 inc si
65 inc di
66 jmp again1
67 exit1:
68 mov byte ptr [di],24h
69 pop di
70 pop si
71 pop cx
72 pop ax
73 ret
74 change endp
75 ;..............................................
76 rechange proc near
77 push ax
78 push cx
79 push si
80 push di
81 mov ax, dseg
82 mov ds, ax
83 lea si,msg
84 lea di,dst
85 again3:
86 mov ax,[si]
87 cmp ax,24h
88 je exit3
89 mov cx,ax
90 sub cx,1
91 mov [di],cx
92 inc si
93 inc di
94 jmp again3
95 exit3:
96 mov byte ptr [di],24h
97 pop di
98 pop si
99 pop cx
100 pop ax
101 ret
102 rechange endp
103 ;.............................................
104 input proc near
105 push ax
106 push cx
107 push si
108 mov ax, dseg
109 mov ds, ax
110 lea si,msg
111 again2:
112 mov ah,1
113 int 21h
114 cmp al,0dh
115 je exit2
116 mov [si],al
117 inc si
118 jmp again2
119 exit2:
120 mov byte ptr [si],24h
121 pop si
122 pop cx
123 pop ax
124 ret
125 input endp
126 ;................................................
127 print proc near
128 push ax
129 push dx
130 push cx
131 push si
132 mov ax, dseg
133 mov ds, ax
134 mov dl,13
135 mov ah,2
136 int 21h
137 mov dl,10
138 mov al,2
139 int 21h
140 mov dx, offset dst
141 mov ah, 09h
142 int 21h
143 pop si
144 pop cx
145 pop dx
146 pop ax
147 ret
148 print endp
149 ;...............................................
150 cseg ends
151 end start

运行结果

posted @ 2011-10-22 13:29  蜗勒个牛  阅读(734)  评论(0编辑  收藏  举报