Question: I have a MIPs project that involves inputting a String value and having it decrypted or encrypting it by subtracting / adding an integer value
I have a MIPs project that involves inputting a String value and having it decrypted or encrypting it by subtracting / adding an integer value in each character's ascii value(an input), then flipping a bit (bitshifting, another input value) and print it back out. I believe I've written the prompt to read and iterate through the string input, but I don't know how to implement or write the subroutines for adding, shifting each character. Any help is appreciative
.data
prompt: .asciiz "enter 'e' or 'd' to encrypt or decrypt:"
inspace: .space 100
plaintext: .asciiz "Enter text to Encrypt: "
encryptedText: .asciiz "Encrypted Text:"
lameText: .asciiz "Enter text to Decrypt:"
decryptedText: .asciiz "Decrypted Text:"
data: .space 100
addKey: .asciiz "Enter addition key:"
toggleKey: .asciiz "Enter bit toggle key:"
wrongInput: .asciiz "Enter a valid input instead"
bitKey: .asciiz "Enter toggle key"
.text
main:
start:
#encrypt or decrypt
la $a0,prompt
li $v0,4
syscall
#read input
la $a0,inspace
la $a1,5
li $v0,8
syscall
lb $t2,0($a0)
# encrypt
beq $t2,101,Plaintext #if $t2 = ascii value e,go to plaintext
# decrypt
beq $t2,100,decryptText #if t2 = ascii value d, go to decryptText
# incorrect input
la $a0,wrongInput
li $v0,4
syscall
# terminates program if a wrong input entered
li $v0,10
syscall
Plaintext:
# Read Plain text value
la $a0,plaintext
li $v0,4
syscall
la $a0,data
la $a1,40 # Maximum 40 characters can be read ( This can be changed )
li $v0,8
syscall
la $t0,($a0) # Entered string is stored in the t0 register
li $t1,0 # string length
# Read Key
la $a0,addKey
li $v0,4
syscall
li $v0,5
syscall
move $t3,$v0
#read shift key
la $a0,bitKey
li $v0,4
syscall
li $v0,5
syscall
move $t2,$v0
Encrypt:
lb $t4, 0($t0) # The first character is read
beq $t4,10,end # Terminate program on the
beqz $t4,end # Terminate Program when the end of the string is reached
jal addShift
PrintEncryptChar:
la $a0,encryptedText
li $v0,11 # print the encrypted character
syscall
add $t0,$t0,1 # Points to the next character
add $t1,$t1,1 # length is incremented
j Encrypt
decryptText:
# Read decrypt text value
la $a0,lameText
li $v0,4
syscall
la $a0,data
la $a1,40
li $v0,8
syscall
la $t0,($a0) # Entered string is stored in the t0 register
li $t1,0 # string length
# Read Key
la $a0,addKey
li $v0,4
syscall
li $v0,5
syscall
move $t3,$v0
#read bitKey
la $a0,bitKey
li $v0,4
syscall
li $v0,5
syscall
move $t2,$v0
Decrypt:
lb $t4, 0($t0) # First character is read
beq $t4,10,end # Terminate program when is pressed
beqz $t4,end # Terminate program when the end of the string is reached
jal subShift
PrintDecryptChar:
la $a0,decryptedText
li $v0,11 # Print the Decrypted character
syscall
add $t0,$t0,1 # Points to the next character
add $t1,$t1,1 # length is incremented
j Decrypt
end:
li $v0,10
syscall
#adding/ subtracting ascii value
addShift:
jr $ra
subShift:
jr $ra
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
