Create a MIPS assembly program using MARS to do RSA encryption/decryption. Get a numeric message from the user and encrypt it. Also, get a numeric message from the user and decrypt it. An RSA public key consists of a pair of numbers (n, e), and the message m is encrypted to a ciphertext c by calculating c = me (mod n). The RSA private key consists of a pair of numbers (n, d), and a ciphertext c is decrypted by calculating m = cd (mod n). For this, use n=21733, e=257, d=1403. Note that since me and cd can get rather large (hundreds or thousands of digits for our examples), use the following pseudocode to handle encryption and decryption: doRSA( n, exp, msg ) cmsg = msg Initialize ciphertext, requires odd exponent mpow = msg message to the power 1, 2, 4, 8, 16, … tempexp = exp temporary exponent while ( tempexp > 1 ) mpow = ( mpow * mpow ) % n square the message tempexp = tempexp / 2 update the power if ( tempexp % 2 == 1 ) 1 bit in the binary representation of e? cmsg = ( cmsg * mpow ) % n include the current power return cmsg Some examples: encrypt( 12345 ) = 9972 decrypt( 9972 ) = 12345 ---------------------------------------------------------------------------------------- I've pasted the code that I have started below. I just don't think I am doing the calculations correctly. Please help. .text getMsg: # ask for a message from the user li $v0, 4 # print prompt for message la $a0, promptMsg # integer for message syscall # get the message as a string li $v0, 5 # get the message as integer into $v0 syscall move $s1,$v0 # save message for use in subroutine .data promptMsg: .asciiz "Enter a message: " .text lw $t1,one lw $t2,two lw $t3,tempExp lw $t4,n __GT1tempExp_: mul $s2,$s1,$s1 # ( mpow * mpow ) div $s2,$s2,$t4 # ( mpow * mpow ) % n div $t3,$t3,$t2 # tempexp = tempexp / 2 # while loop while tempexp is greater than one ble $s2,$t1,__LT1tempExp_ # branch if tempexp is > 1 __CheckBit: bne $t3,$zero,__CheckBit # Check if exponent is 1 bc1t __LT1tempExp_ __LT1tempExp_: mul $s3,$s1,$s2 # ( cmsg * mpow ) div $s3,$s3,$t4 # ( cmsg * mpow ) % n mfhi $s3 .data tempExp: .word 257 one: .word 1 two: .word 2 n: .word 21733
Create a MIPS assembly program using MARS to do RSA encryption/decryption. Get a numeric message from the user and encrypt it. Also, get a numeric message from the user and decrypt it. An RSA public key consists of a pair of numbers (n, e), and the message m is encrypted to a ciphertext c by calculating c = me (mod n). The RSA private key consists of a pair of numbers (n, d), and a ciphertext c is decrypted by calculating m = cd (mod n).
For this, use n=21733, e=257, d=1403.
Note that since me and cd can get rather large (hundreds or thousands of digits for our examples), use the following pseudocode to handle encryption and decryption:
doRSA( n, exp, msg )
cmsg = msg Initialize ciphertext, requires odd exponent
mpow = msg message to the power 1, 2, 4, 8, 16, …
tempexp = exp temporary exponent
while ( tempexp > 1 )
mpow = ( mpow * mpow ) % n square the message
tempexp = tempexp / 2 update the power
if ( tempexp % 2 == 1 ) 1 bit in the binary representation of e?
cmsg = ( cmsg * mpow ) % n include the current power
return cmsg
Some examples:
encrypt( 12345 ) = 9972
decrypt( 9972 ) = 12345
----------------------------------------------------------------------------------------
I've pasted the code that I have started below. I just don't think I am doing the calculations correctly. Please help.
.text
getMsg:
# ask for a message from the user
li $v0, 4 # print prompt for message
la $a0, promptMsg # integer for message
syscall
# get the message as a string
li $v0, 5 # get the message as integer into $v0
syscall
move $s1,$v0 # save message for use in subroutine
.data
promptMsg: .asciiz "Enter a message: "
.text
lw $t1,one
lw $t2,two
lw $t3,tempExp
lw $t4,n
__GT1tempExp_:
mul $s2,$s1,$s1 # ( mpow * mpow )
div $s2,$s2,$t4 # ( mpow * mpow ) % n
div $t3,$t3,$t2 # tempexp = tempexp / 2
# while loop while tempexp is greater than one
ble $s2,$t1,__LT1tempExp_ # branch if tempexp is > 1
__CheckBit:
bne $t3,$zero,__CheckBit # Check if exponent is 1
bc1t __LT1tempExp_
__LT1tempExp_:
mul $s3,$s1,$s2 # ( cmsg * mpow )
div $s3,$s3,$t4 # ( cmsg * mpow ) % n
mfhi $s3
.data
tempExp: .word 257
one: .word 1
two: .word 2
n: .word 21733
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)