Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

28. For s Answered: 1 week ago

Answered: 1 week ago

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

Commen Name with scientific name Tiger - Wolf- Lion- Cat- Dog-

Answered: 1 week ago