2014-12-10 21 views
-1

:這是我得到告訴現在我怎樣才能得到這個程序:單數字替代加密? (一個由1ž分至26)

include emu8086.inc 

DEFINE_GET_STRING 


;      'abcdefghijklmnopqrstvuwxyz' 

jmp start 

buffer db "     ",0dh,0ah,'$' 
size = $ - offset buffer ; declare constant 

table2 db 'abcdefghijklmnopqrstvuwxyz' 

table1 db 97 dup (' '), 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 


start: 
lea  di, buffer  ; buffer offset. 
mov  dx, size  ; buffer size. 
call get_string 
putc 0dh 
putc 0ah 
; encrypt: 
lea bx, table1 
lea bp, di 
call parse 

; show result: 
;lea dx, di 
; output of a string at ds:dP 

putc 0ah 
putc 0dh 

; decrypt: 
lea bx, table2 
lea bp,di 
call hamdy 

; show result: 
call print_string 


; 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 

osama: 
    cmp [bp] , '$' ; end of string? 
    je end_of_string 

    mov al, [bp] 
    cmp al, 'a' 
    jb skip 
    cmp al, 'z' 
    ja skip  
    ; xlat algorithm: al = ds:[bx + unsigned al] 
    xlatb  ; encrypt using table2. 
    mov [bp], al 
    mov ah,0 
    call print_num_uns 
skip: 
    inc bp 
    jmp osama 

end_of_string: 


ret 
parse endp 


hamdy proc near 

osama_1: 
    cmp [bp] , '$' ; end of string? 
    je end_of_string_1 

    mov al, [bp] 
    cmp al, 1 
    jb skip_1 
    cmp al, 26 
    ja skip_1 
    ; xlat algorithm: al = ds:[bx + unsigned al] 
    xlatb  ; encrypt using table2. 
    mov [bp], al 
    mov ah,0 
skip_1: 
    inc bp 
    jmp osama_1 

end_of_string_1: 


ret 
hamdy endp 

DEFINE_PRINT_NUM_UNS 
DEFINE_PRINT_STRING 
end 
+1

這個問題可以通過解釋你所嘗試的以及你在哪裏遇到麻煩來改進。 – ComputerDruid 2014-12-11 01:00:33

回答

0

一個。如果對GET_STRING的調用總是成功,我會感到驚訝。

lea  di, buffer  ; buffer offset. 
mov  dx, size  ; buffer size. 
call get_string 

我猜大小不應該包括終止回車,換行符和美元字符。我建議你的代碼:

size = ($-3) - offset buffer ; declare constant 

b。您的TABLE2需要從一個額外的字節開始!

table2 db 0,'abcdefghijklmnopqrstvuwxyz' 

或者您可以在翻譯前減少AL。

dec al 
xlatb  ; encrypt using table2 

c。同樣,您可以通過編碼來消除在TABLE1的定義中使用那些97個空格:

mov al, [bp] 
cmp al, 'a' 
jb skip 
cmp al, 'z' 
ja skip  
; xlat algorithm: al = ds:[bx + unsigned al] 
sub al,'a' 
xlatb  ; encrypt using table1. 
mov [bp], al 

d。對你的PARSE例程的評論是錯誤的。前

;    si - address of string to encrypt  --> Is bp 

xlatb  ; encrypt using table2     --> Is table1 
0

1)調用print_num_uns有一個缺失行從SI寄存器print_num_uns打印所以u需要

到LEA,SI,二第一

LEA SI, di

call print_num_uns

2)您需要在表格2中的abc之前放置一些字符(空格,零或任何其他字符),因爲在表格1中,索引爲98,但'a'默認索引爲97,所以它需要在數組之前

相關問題