Question: I am trying to convert C code to a working translation of Y 8 6 - 6 4 assembly . Here is the code in
I am trying to convert C code to a working translation of Yassembly Here is the code in C:
Function to encrypt a message using Caesar cipher
void encryptchar message int shift
while message
if message a && message z
message message a shifta;
else if message A && message Z
message message A shiftA;
message;
Function to decrypt a message using Caesar cipher
void decryptchar message int shift
encryptmessage shift; Decryption is just encryption with shift original shift
This code encodes and decodes strings using a Caesar cipher. This program introduces the manipulation of character arrays and the application of modular arithmetic in assembly language.
For the Caesar Cipher operation, the assembly language program should handle encryption and decryption of strings based on a given shift value. The stack will be prepared as follows before calling the routine:
The shift value will be pushed onto the stack first. This integer determines the number of positions each character is shifted in the alphabet for encryption or decryption.
Next, the bit pointer to the message string that will be encrypted or decrypted will be pushed onto the stack.The message string is nullterminated.
In this setup, message is at the top of the stack, directly accessible by the routine, and shift is just beneath it
The routine should iterate over each character of the message, checking if it is an alphabetic character. For each alphabetic character, apply the shift, accounting for both uppercase and lowercase letters. The shift must wrap around the alphabet, meaning that after z it goes back to a and similarly, after Z it returns to A Nonalphabetic characters should remain unchanged.
The modified message string, now encrypted or decrypted, will be in the same memory location as the input. The routine does not need to return any value in rax since the operation modifies the message string in place. Before returning to the caller, ensure the stack is correctly restored if modified during the routine.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
