Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a procedure that performs simple encryption by rotating each plaintext byt

ID: 3696602 • Letter: W

Question

Write a procedure that performs simple encryption by rotating each plaintext byte a varying number of positions to the left based on the key value.

The integer in each position indicates the magnitude of the rotation: key BYTE 1, 7, 2, 3, 5, 4, 6

Your procedure should loop through a plaintext message and align the key to the first 7 bytes of the message. Rotate each plaintext byte by the amount indicated by its matching key array value. Then, align the key to the next 7 bytes of the message and repeat the process. Write a program that tests your encryption procedure by calling it twice, with different data sets. Print the original and encrypted plaintext.

This is in assembly language.

Explanation / Answer

TITLE Encryption Using Rotate Operations(Encrypt asm)
;THis program clears the screen, inputs the plain text from; user,encrypt it & then

;display the cipher text
INCLUDE Irvine32.inc
BUFMAX=128
.data
strText BYTE "Enter the plain text:', 0
strEnc BYTE "The encrypted textis:', 0
buffer BYTE BUFMAX+1 DUP(0)
bufSize DWORD ?
key SBYTE 1,7,2,3,5,4,6
keySize DWORD 10
.code
main PROC
;calls the procedures
call clrscr; clears the screen
mov ecx, 2
L1:
call DisplayText; displays the encrypted text
loop L1
exit
main ENDP
InputPlain Text PROC USES ecx.edx
;inputs the plain text from user
;Receives: Nothing
;Returns: Nothing
mov ed x, OFFSET strText
call WriteString; writes the string str Text
call Crif
mov ecx, BUFMAX; store maximum buffer lenght
mov edx, OFFSET buffer
call ReadString;read the bufferin EAX
mov bufSize,eax; store the input buffer lenght
call Crif
ret
InputPlain Text ENDP
ConvertText PROC USES esi ecx edx
;encrypts the plain text to get the cipher text
;Receives: Nothing
;Returns: Nothing
mov ecx, bufSize; convert each character of buffer text
mov edx,0; initialize index of key
movesi,0; initialize index of buffer
Label1:
cmp key[edx],0; convert the buffer text
jl Label2; if keyvalue<0, jump to Lable2
shr buffer[esi],key[edx]; positive key value,
rotate to right
inc esi
inc edx
jpm Lable3
Label2:
shl buffer[esi],key[edx]; negative key value.
rotate to left
inc esi
inc edx
Label3:
cmpedx,keySize; check keyindex=keysize
jne Lable1; jump to Label1 and continue the loop
mov edx,0; reinitialize key index to 0
loop Label1
ret
ConvertText ENDP
;Display the encrypted text that is the content of buffer
;Receives: Nothing
;Returns: Nothing
mov edx, OFFSET strEnc
call WriteString
mov edx, OFFSET buffer
call WriteString; write the buffer content
call Crif
call Crif
ret
DisplayText ENDP

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote