Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encryption of characters entered into a buffer

Status
Not open for further replies.

babez

Programmer
Jan 3, 2007
4
0
0
GB
please could you help me i have a file :
Listing 1
.model small
.stack 100h

.data
buffer db 100 dup(0)
entry db "Welcome to simple edit program",0ah,0ah,'$'
enter db "Please enter character - ESC to leave",0ah,0dh,'$'
endit db "Terminate the program",0ah,0dh,'$'

.code

; A marco for printing messages..
mdisplay macro string
push ax ;push ax onto the stack
push dx ;same for dx
mov ah,9 ;service 9 (drint a string).
mov dx,offset string ;the string to print
int 21h ;do it!
pop dx ;pop dx off stack
pop ax ;pop ax off stack
endm
; to end the marco..

main proc near
mov ax,@data
mov ds,ax
mdisplay entry
;-----------------------------------------
mov bx,offset buffer
mdisplay enter
.repeat
call readkey ;read a key value
call dispch ;echo to screen
mov byte ptr[bx],al ;store in buffer
inc bx ; increment buffer pointer
.until (bx == offset buffer+100 || [bx-1]==1bh)
mdisplay endit
;----------------------------------------
mov ax,4c00h
int 21h
;ret
main endp

;------------------------
readkey proc near
mov ah,0
int 16h
ret
readkey endp
;------------------------
dispch proc near
push bx
mov bx,0
mov ah,14
int 10h
pop bx
ret
dispch endp
end

I need to modify the above program in order to encrypt text entered using a key someting like the following:

.model small
.stack 100h
XORVAL = 111 ;could be any value between 0-255
.code
main proc near
mov ax,@data
mov ds,ax ;don't really need access to data segment.
L1:
mov ah,6 ;direct console input
mov dl,0ffh ;don't wait for character (coming from a file).
int 21h ;will return character in AL.
jz L2 ;quit reading if zero (ZF=1) since EOF.
xor al,XORVAL ;encrypt the data with our key.
mov ah,2 ;write data to output.
mov dl,al ;wants to see data in dl.
int 21h ;do it!
jmp L1 ;if it gets to here jump back to L1 and repeat.
L2:
mov ax,4c00h ;get ready to quit program and return to DOS.
int 21h ;teminate the program here.
main endp
end

but this only encrypts from a file if you enter at the dos prompt "test < plain > coded" using the aside program

any ideas?
 
the exor val is fine, i need to encorporate both scripts to be able to encript some text entered by the user which can then be put back into plain text to be able to read it.
the ex or value is the key that will encrypt the users input.
The second script i have above when used encrypts a plain.txt file contents which i can then de-crypt to see it clearly again.
any more ideas?
 
some thing like this??

mov ah,0ah ; buffer keyboard input
lea dx,parameter
int 21h

call nextline

mov ah,09 ; display string
lea dx,namefield
int 21h

mov ax,4c00h
int 21h

parameter label byte
maxlen db 30
actlen db ?
namefield db 28 dup('$')

nextline:
mov ah,02
mov dl,0ah
int 21h
mov dl,0dh
int 21h
ret
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top