MIPS Assignment In this assignment I am to encrypt and decrypt a message using s
ID: 3601978 • Letter: M
Question
MIPS Assignment
In this assignment I am to encrypt and decrypt a message using symmetric encryption. There are three methods left for me to write: Hash method, encrypt method, and decrypt method.
Correct output will look like:
Original message text:
This string will be encrypted.
Encrypted text (hex):
0x3344c899
0xf29993ad
0xe0ca4e24
0x6c01097a
0x6048c2ed
0xf28e8ee8
0xa5d95034
0x006d4e69
0x00000000
0x00000000
Decrypted text:
This string will be encrypted.
Here is my code so far, do NOT change anything in this code please, thank you.
.data
Key:
.word 0x1234ABCD
Messagetext:
.asciiz "This string will be encrypted."
Output1:
.asciiz "Original message text: "
Output2:
.asciiz " Encrypted text (hex): "
Output3:
.asciiz " Decrypted text: "
CR:
.asciiz " "
.align 2
Ciphertext:
.space 40
.align 2
Plaintext:
.space 40
.text #most of this code is string printing
la $a0, Output1
addi $v0, $0, 4
syscall
la $a0, Messagetext
addi $v0, $0, 4
syscall
la $a0, CR
addi $v0, $0, 4
syscall
la $a0, Messagetext
la $a1, Ciphertext
jal Encrypt #encrypt the message text to the ciphertext buffer
la $a0, Output2
addi $v0, $0, 4
syscall
la $a0, Ciphertext
jal PrintBufferHex #print out the hex of the ciphertext
la $a0, CR
addi $v0, $0, 4
syscall
addi $a0, $a1, 0
la $a1, Plaintext
jal Decrypt #decrypt the cipher text to plaintext
la $a0, Output3
addi $v0, $0, 4
syscall
addi $a0, $a1, 0
addi $v0, $0, 4
syscall
la $a0, CR
addi $v0, $0, 4
syscall
addi $v0, $0, 10 #end of program
syscall
PrintBufferHex: #subroutine which prints buffer in hex
addi $sp, $sp, -4
sw $a0, ($sp)
addi $t0, $a0, 0
addi $t1, $0, 10
PrintLoop:
addi $v0, $0, 34
lw $a0, ($t0)
syscall
la $a0, CR
addi $v0, $0, 4
syscall
addi $t0, $t0, 4
addi $t1, $t1, -1
bne $t1, $0, PrintLoop
lw $a0, ($sp)
addi $sp, $sp, 4
jr $ra
Encrypt:
#your code goes here
-- program is finished running --
Explanation / Answer
Encrypted text (hex):
0x3344c899
0xf29993ad
0xe0ca4e24
0x6c01097a
0x6048c2ed
0xf28e8ee8
0xa5d95034
0x006d4e69
0x00000000
0x00000000
Decrypted text:
This string will be encrypted.
Here is my code so far, do NOT change anything in this code please, thank you.
.data
Key:
.word 0x1234ABCD
Messagetext:
.asciiz "This string will be encrypted."
Output1:
.asciiz "Original message text: "
Output2:
.asciiz " Encrypted text (hex): "
Output3:
.asciiz " Decrypted text: "
CR:
.asciiz " "
.align 2
Ciphertext:
.space 40
.align 2
Plaintext:
.space 40
.text #most of this code is string printing
la $a0, Output1
addi $v0, $0, 4
syscall
la $a0, Messagetext
addi $v0, $0, 4
syscall
la $a0, CR
addi $v0, $0, 4
syscall
la $a0, Messagetext
la $a1, Ciphertext
jal Encrypt #encrypt the message text to the ciphertext buffer
la $a0, Output2
addi $v0, $0, 4
syscall
la $a0, Ciphertext
jal PrintBufferHex #print out the hex of the ciphertext
la $a0, CR
addi $v0, $0, 4
syscall
addi $a0, $a1, 0
la $a1, Plaintext
jal Decrypt #decrypt the cipher text to plaintext
la $a0, Output3
addi $v0, $0, 4
syscall
addi $a0, $a1, 0
addi $v0, $0, 4
syscall
la $a0, CR
addi $v0, $0, 4
syscall
addi $v0, $0, 10 #end of program
syscall
PrintBufferHex: #subroutine which prints buffer in hex
addi $sp, $sp, -4
sw $a0, ($sp)
addi $t0, $a0, 0
addi $t1, $0, 10
PrintLoop:
addi $v0, $0, 34
lw $a0, ($t0)
syscall
la $a0, CR
addi $v0, $0, 4
syscall
addi $t0, $t0, 4
addi $t1, $t1, -1
bne $t1, $0, PrintLoop
lw $a0, ($sp)
addi $sp, $sp, 4
jr $ra
Encrypt:
#your code goes here
-- program is finished running --
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.