当前位置: 首页 > 文档资料 > 汇编中文教程 >

LODS

优质
小牛编辑
134浏览
2023-12-01

在密码学中,凯撒密码是最简单的已知加密技术之一。 在该方法中,要加密的数据中的每个字母被字母表中的一些固定数量的位置的字母替换。

在这个例子中,让我们通过简单地用两个字母的移位替换其中的每个字母来加密数据,因此a将被替换为cbd替换,依此类推。

我们使用LODS将原始字符串'password'加载到内存中。

section .text
   global _start         ;must be declared for using gcc
_start:                  ;tell linker entry point
   mov    ecx, len
   mov    esi, s1
   mov    edi, s2
loop_here:
   lodsb
   add al, 02
   stosb
   loop    loop_here          
   cld
   rep     movsb
   mov     edx,20        ;message length
   mov     ecx,s2        ;message to write
   mov     ebx,1         ;file descriptor (stdout)
   mov     eax,4         ;system call number (sys_write)
   int     0x80          ;call kernel
   mov     eax,1         ;system call number (sys_exit)
   int     0x80          ;call kernel
section .data
s1 db 'password', 0 ;source
len equ $-s1
section .bss
s2 resb 10               ;destination

编译并执行上述代码时,会产生以下结果:

rcuuyqtf