【发布时间】:2015-06-17 07:14:56
【问题描述】:
问题:
编写一个程序,通过将每个明文字节旋转一个变化来执行简单加密
不同方向的位置数。例如,在下面的数组中表示
加密密钥,负值表示向左旋转,正值表示
向右旋转。每个位置的整数表示旋转的幅度:
关键字节 -2、4、1、0、-3、5、2、-4、-4、6
代码:
Include Irvine32.inc
.data
msg BYTE "Hello", 0
key BYTE -2, 4, 1, 0, -3, 5, 2, -4, -4, 6
.code
main proc
mov ecx, LENGTHOF key ;Loop Counter
mov edx, OFFSET msg ;EDX Holds msg and will Display it
mov esi, OFFSET key ;Point to first array element
mov ebx, 0 ;CMP number
top:
cmp [esi], ebx ;if esi < ebx
jl ShiftLeft ;jump to shift left
cmp [esi], ebx ;if esi > ebx
jg ShiftRight ;jump to shift right
cmp [esi], ebx
je NoShift
ShiftLeft:
mov cl, [esi]
SHL edx, cl
add esi, TYPE key
loop top
ShiftRight:
mov cl, [esi]
SHR edx, cl
add esi, TYPE key
loop top
NoShift:
add esi, TYPE key
loop top
call WriteString
invoke ExitProcess,0
main endp
end main
所以我遇到了一些问题。
1. cmp 语句是相反的。所以第一个 cmp 应该是 cmping -2 和 0。-2
2. 我是否使用 add esi, TYPE 键行正确地递增到下一个数组索引?
3. 我理解这个问题吗?如果数组中的数字为负数,我需要将我的消息“Hello”向左旋转,如果数组中的数字为正数,则向右旋转。
任何帮助都很好,在此先感谢。
【问题讨论】:
标签: arrays assembly x86 masm irvine32