text encryption

hi!i have a problem with the code below, the code is supposed to work like this:

characters from a to z are assigned integers with a=0,b=1and z=25.
the user is prompted tp enter a key i.e a series of characters between a and z - the length doesnot matter

the user is then prompted to enter plain text to encrypt,an encrypted character is then defined as the sum of a plain text character and a key character modulo 26.

now my code is givin me problems when i try to enter the key it only accepts one character and does not allow me to enter text to encrypt

this is how far i went with the code


include pcmac.inc

.MODEL SMALL
DOSSEG

.STACK 100h

.DATA

prompt db 'ENTER KEY:',13,10,'$'

prompt2 db 'ENTER PLAIN TEXT TO ENCRYPT:',13,10,'$'

output db 'output:',13,10,'$'

Achar db 50 dup(0)
Keyval db 50 dup(0)


.CODE


main proc

mov ax,@data
mov ds,ax

_PutStr prompt

_GetCh
mov di,offset keyval


Getkey:

cmp al,13
jne next

cmp al,'a'
jnge done

cmp al,'2'
jnle done

sub al,'a'
mov [di],al
inc di

jmp Getkey


next :
_Putstr prompt2
_GetCh
mov di,offset Achar

mov cx,0

Gettext:

cmp al,13
je next
cmp al,'a'
mov [di],al

inc di
inc cx
_GetCh
jmp Gettext

next1 :

_Putstr output
jcxz done
mov si,offset keyval
mov di,offset Achar


out1:

mov al,[si]
cmp al,0
jne out2
mov si,offset keyval
mov al,[si]
out2:
add al,[di]
mov ah,0
cwd
mov bx,26
div bx
add dl,'a'

_Putch dl

inc si
inc di

loop out1



done:

_Exit 0

main endp

end main






Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories