【问题标题】:encrypt decrypt nasm asm file using stosb and lodsb hw使用 stosb 和 lodsb hw 加密解密 nasm asm 文件
【发布时间】:2015-04-06 18:43:23
【问题描述】:

我几天来一直在尝试编写一个 nasm asm 文件,该文件使用 stosb 和 lodsb 来获取用户输入,并使用“异或”来有效地对其进行加密,然后将其显示在屏幕上,然后解密并显示在屏幕上。我试图使用另一个做类似事情的 asm 文件并对其进行逆向工程,但我无法通过 stosb 加载字符串并使用 lodsb 输出字符串。打印到屏幕部分是我试图打印使用 stosb 存储的内容的地方。此外,我打算在 stosb 和 lodsb 工作后修改编码器解码部分。任何帮助将不胜感激。

    ; read a string
    ; encrypt it, and decrypt it.

        org 100h

    section .data
    ;___________________________DATA
    prompt1: db "What is your secret message? $"
    prompt2: db "The encrypted message is: $"
    prompt3: db "The message after decryption is: $"
    testout: db "*************** $"

   key  db  0Fh         ; encryption key*
   CRLF db  13, 10, '$'     ; carriage return line feed
   NULL db  0           ; null character

   section  .bss                ; bss section*
   buffer   resb 80             ; 80 reserve bytes*

   section .text

   ;_____________________________SCREEN TEXT
   mov  ah, 9           ; Used to print text stored in prompt1
mov dx, prompt1     ; 
int 21h         ; end text output

;_______________________INSTRING (KEYBOARD INPUT)
instring:
mov cx, 0           ; CX counts characters starts at 0

cld             ; process string left to right*
mov di, buffer      ; move buffer into data index*

mov ah, 1           ; read character from standard input*
int 21h         ; read character*   
while1: cmp al, 13          ; is character carriage return*
je  endwhile1       ; if carriage return exit loop*
inc cx          ; increment cx*
stosb               ; store character just read into buffer*
int 21h         ; read next character*
jmp while1          ; loop until all characters read*
endwhile1:              ; endwhile1 (end of loop)*
mov byte [di], NULL     ; store ASCII null character (end of array)*
mov dx, buffer      ; dx is the address arg to print*?

;__________________________PRINT TO SCREEN
lp:

cld             ; process string left to right*
lodsb
mov dl, al
mov ah, 2
int 21h
loop    lp

;___________________________CODER (encode data)
;   mov si,0            ; string index register(si = string index)***
;while1:    
;   cmp byte [si+msg],'$'   ; looks for "$" to end loop***
;   je  endwhile1       ; "$" ends loop***
;   mov al,[si+msg]     ; moving through msg one character at a time***
;   xor al,[key]        ; XOR value stored in al (encode)***        
;   mov [si+coded],al       ; move encoded character to al***
;   inc si          ; increment si (array index counter)***
;   jmp while1          ;
;endwhile1:
;   
;   mov byte [si+coded],'$'
;   
;   mov ah,9            ; write string to standard output ***
;   mov dx,coded        ; store coded in output register ***
;   int     21h         ; output coded ***
;
;
;___DECODE SECTION
;   mov si,0
;while2:    
;   cmp byte [si+coded],'$'
;   je  endwhile2
;   mov al,[si+coded]
;   xor al,[key]
;   mov [si+decoded],al
;   inc si
;   jmp while2
;endwhile2:
;   
;   mov byte [si+decoded],'$'
;
;___DECODED SCREEN OUTPUT   
;   mov ah,2            ; write characer to standard output***
;   mov dl,13           ; store carrage carriage return code***
;   int 21h         ; output carriage return***
;   mov dl,10           ; line feed code***
;   int 21h         ; output line feed***
;   
;   
;   mov ah,9            ; write string to standard output ***
;   mov dx,decoded      ; store decoded in output register ***
;   int     21h         ; output decoded ***
;

exit:
    mov ah, 04Ch        ; DOS function: Exit program
    mov al, 0           ; Returns exit code value
    int 21h         ; Call DOS (Terminate Program)

【问题讨论】:

  • 欢迎来到 SO。我假设您正在尝试在 DOS/Windows 下执行此操作(因为您正在调用 21h)。如果这是真的,您能否添加更多有关您使用的操作系统的信息?
  • 在窗口机器上使用 nasm 和 dosbox(模拟器)。 8086处理器

标签: assembly encryption nasm x86-16


【解决方案1】:
mov dx, buffer      ; dx is the address arg to print*?
;__________________________PRINT TO SCREEN
lp:
cld             ; process string left to right*
lodsb
mov dl, al
mov ah, 2
int 21h
loop    lp

您必须将地址放入 SI 寄存器(而不是 DX 寄存器)。
循环内不需要 CLD。在循环之前执行一次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    • 2021-10-20
    • 1970-01-01
    • 2011-01-27
    相关资源
    最近更新 更多