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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Public key encryption
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education