Question

In: Computer Science

Writing a caesar cipher in ARM assembly. INSTRUCTIONS: Step 1: The first thing you should do...

Writing a caesar cipher in ARM assembly.

INSTRUCTIONS:

Step 1:
    The first thing you should do is modify the case conversion program String.s (provided)
    Instead of subtracting 32 from all numbers you want to add a constant number which we will call the key.
    Assume that all input will be lowercase. 
    So it'll look like this,
        k = 2;
        letter = 'a';
        newletter = k+letter;
    Above is pseudocode and ABOVE NOT ASSEMBLY CODE DO NOT COPY.
    Use bl puts to show that everything is working correctly.
    You should hard code the plaintext in the assembly file.
Step 2:
    If the key + letter is bigger is 'z' then you have to subtract 26.
    If the key + letter is less than 'a' then you have to add 26.

STRING.S

.text
.global main

main:
    ldr r4,=string

get_another_byte:
    ldrb r5,[r4]

    cmp r5,#'a'
#    blt keep_going
#    cmp r5,#'z'
#    bgt keep_going

    subeq r5,#32
    strbge r5,[r4]

keep_going:
    add r4,#1
    cmp r5,#0
    bne get_another_byte

    ldr r0,=temp
    str lr,[r0]

    ldr r0,=string
    bl puts

    ldr r0,=temp
    ldr lr,[r0]

    bx lr

.data

string:
.asciz "This is a string |"


temp:
    .word 0

Solutions

Expert Solution

Solution: Below is the code for caesar cipher in ARM assembly

PRESERVE8
AREA vectors, CODE, READONLY
EXPORT __Vectors
__Vectors
DCD 0x20008000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector
ALIGN

;————————————————–
; Data area
;————————————————–
AREA MyData, DATA, READWRITE
EXPORT Ciphertext, Deciphertext
Ciphertext SPACE 100 ; space to save cipher text
Deciphertext SPACE 100 ; space to save deciphered text
ALIGN

AREA MainProgram, CODE, READONLY

;————————————————–
; Key to use for the cipher
;————————————————–
Key DCD 33
;————————————————–
; String to cipher
;————————————————–
Plaintext DCB “This is a sample text to be used with the Caesar’s Cipher.\n”,0
ALIGN

ENTRY
EXPORT Reset_Handler
;————————————————–
; Start of code
;————————————————–
Reset_Handler

; Cipher plaintext using Caesar’s cipher
ldr R0,=Key ; load cipher key in R0
ldr R0,[R0]
ldr R1,=Plaintext ; load plaintext address in R1
ldr R2,=Ciphertext ; load ciphertext address in R2
bl Caesar_Cipher ; cipher plaintext

; here, variable Ciphertext will have the plaintext cipher

;Now test the deciphering using the negative key
ldr R0,=Key ; load cipher key in R0
ldr R0,[R0]
neg R0, R0 ; convert to negative
ldr R1,=Ciphertext ; load ciphertext address in R1 (use as plaintext argument)
ldr R2,=Deciphertext ; load deciphertext address in R2 (use as ciphertext argument)
bl Caesar_Cipher ; cipher ciphertext

; here, variable Deciphertext will have the original plaintext

endloop ; infinite loop to end program
B endloop

;————————————————–
; Procedure to cipher a text using Caesar’s cipher
; On entry:
; R0 = Key
; R1 = address of zero-terminated plain text
; R2 = address of space to save ciphertext
;————————————————–
Caesar_Cipher PROC
push {R0-R3, LR}
_loop
ldrb R3, [R1], #1 ; load character from plaintext
cmp R3, #0 ; see if we reached the end of text
beq _endcipher ; if so, end cipher loop
cmp R3, #32 ; see if character is < 32
blt _save ; if so, don’t cipher, only save
cmp R3, #127 ; see if character is >= 127
bge _save ; if so, don’t cipher, only save

add R3, R3, R0 ; else, use key to cipher the character
cmp R3, #32
addlt R3, #95 ; if after ciphering is < 32, wrap around
cmp R3, #127
subge R3, #95 ; if after ciphering is >=127, wrap around

_save
strb R3, [R2], #1 ; save character in ciphertext
b _loop ; repeat
_endcipher
pop {R0-R3, LR}
bx lr ; return to caller
ENDP
ALIGN

END

**Fell free to ask any queries in the comment section. I am happy to help. if you like our work, please upvote**


Related Solutions

Writing a statically allocated linked list in ARM assembly (raspberry pi). Step 1: You will statically...
Writing a statically allocated linked list in ARM assembly (raspberry pi). Step 1: You will statically allocate some space for your link list elements. You need to make 5 elements, each elements should have two components, the next pointer first then the value stored. First initialize next pointer to NULL. The value stored at the address will be a string pointer. Step 2: You will then write a function that links the statically allocated linked list elements together. Step 3:...
Step 1: The first thing you should do is modify the case conversion program that Neil...
Step 1: The first thing you should do is modify the case conversion program that Neil did in class. Instead of subtracting 32 from all numbers you want to add a constant number which we will call the key. Assume that all input will be lowercase. So it'll look like this, k = 2; letter = 'a'; newletter = k+letter; Above is pseudocode and ABOVE NOT ASSEMBLY CODE DO NOT COPY. Use bl puts the same way Neil did in...
What is the FIRST thing you should do when you speak to this community about the...
What is the FIRST thing you should do when you speak to this community about the risk from the PFAS contamination? (select one option only) Discuss sources of scientific uncertainty Compare the magnitude of this risk to other risks Express empathy and understanding Present and explain the results of testing
Assignment: Square Matrix ("Caesar Block")Cipher C++ ASSIGNMENTS *REMEMBER IT SHOULD NOT ONLY READ ONE LINE OR...
Assignment: Square Matrix ("Caesar Block")Cipher C++ ASSIGNMENTS *REMEMBER IT SHOULD NOT ONLY READ ONE LINE OR A SINGLE WORD remember, read, understand, and use the waterpump.cpp program will process an arbitrary amount of input text, however long. Arrange a stream in a two dimensional array of characters by filling up the array a line at a time, from leftmost column to rightmost column. DO NOT USE A GETLINE: this program should be able to input an entire library, not a...
Step 1: Think about the last time you used instructions to do something. Step 2: Answer...
Step 1: Think about the last time you used instructions to do something. Step 2: Answer the following questions: What did you use the instructions to do? Did you follow the instructions perfectly, that is, going through each step as it was listed? Why or why not? Did you find the instructions easy to follow? If yes, what specific element made the instructions easy? Did you find the instructions difficult? If yes, why?
The first step in writing a software application is to determine the requirements. There is no...
The first step in writing a software application is to determine the requirements. There is no value in writing a program that does not address the needs of the client. Requirements can be gathered in many ways, but ultimately, the requirements serve to document what the application should and should not do. After the requirements are written, the application design can be prepared, followed by the actual coding. For this project, you will gain some practice in the design phase...
Please clear writing and explain step by step this should be a simple question Consider the...
Please clear writing and explain step by step this should be a simple question Consider the function f : [0,1]→R defined by (f(x) =0 if x = 0) and (f(x)=1 if 0 < x≤1) (i)Compute L(f) andU(f). (ii) Is f Riemann integrable on [0,1]?
Writing Assignment #1 Instructions The following assignment should be typed and printed or handwritten and turned...
Writing Assignment #1 Instructions The following assignment should be typed and printed or handwritten and turned in to the CA office in room​ 201 TMCB.​ If there is no one in the CA Office, you can slip your assignment through the slot in the door. You must follow the instructions below or you will not receive credit.​ You can turn in the assignment up until 5:00 PM on the due date. Important Notices: If you do not staple multiple pages,...
1. Monoalphabetic substitution (using the Caesar Cipher tool right) Encipher (convert plaintext into ciphertext): meal times...
1. Monoalphabetic substitution (using the Caesar Cipher tool right) Encipher (convert plaintext into ciphertext): meal times  Decipher (convert ciphertext in to plaintext):  JR PHDQ JUHHQ 2. Polyalphabetic substitution (using the Vigenere Square in the lecture slide) Encipher: fall  Decipher:  VPX TWOKM
Step 1: The first part of the instructions/rubric is to discuss a reason why contractionary policy...
Step 1: The first part of the instructions/rubric is to discuss a reason why contractionary policy should be used. What kind of things can happen in the economy to cause the Fed to need to use contractionary monetary policy? What kind of things would they look for to let them know that the economy is growing too fast and needs to slow down? Step 2: The next part of the instructions is to explain how each of the three tools...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT