COS 126
RSA
Public-Key Cryptosystem Warmup
|
Programming Assignment 9
Due: Wednesday, 11:59pm |
Overview.
Write a program to implement the RSA public-key cryptosystem.
The RSA (Rivest-Shamir-Adleman)
cryptosystem is widely used for secure communication
in browsers, bank ATM machines, credit card machines,
mobile phones, smart cards, and the Windows operating system.
It works by manipulating large integers.
To thwart eavesdroppers, the RSA cryptosystem must manipulate
large integers (hundreds of digits). The built-in C type int
is only capable of dealing with 16 or 32 bit integers, providing little
or no security.
You will design, implement, and analyze an extended precision
arithmetic data type that is capable of manipulating much
larger integers. You will use this data type to write a client program
that encrypts and decrypts messages using RSA.
Note: the training wheels are off on this assignment - you're
starting with a blank screen, not our code.
This means that you must pay particular attention to the process of
building up your program from scratch. Consider carefully how your
program should be structured and how you are going to implement
the various functions before plunging in.
Remember to thoroughly test and debug each function as you write it.
The RSA cryptosystem.
As discussed in Lecture S1, the RSA public key cryptosystem involves
three integers d, e, and n that
satisfy certain mathematical properties.
The private key (d, n) is
known only by Bob, while the public key
(e, n) is published on the Internet.
If Alice wants to send Bob a message (e.g., her credit
card number) she encodes her message as an integer M
that is between 0 and n-1.
Then she computes:
E(M) = Me mod n
and sends the integer E(M) to Bob.
As an example, if M = 2003, e = 7, d = 2563, n = 3713, then Alice
computes
E(M) = 20037 mod 3713 = 129,350,063,142,700,422,208,187 mod 3713 = 746.
When Bob receives the
encrypted communication E(M), he decrypts it by computing:
M = E(M)d mod n.
Continuing with the example above, Bob recovers the original message by computing:
M = 7462563 mod 3713 = 2003.
To check your arithmetic, you may use bc, maple, or
xmaple.
Part 1 (extended precision arithmetic).
The RSA cryptosystem is easily broken if the private key d or
the modulus n are too small (e.g., 32 bit integers).
The built-in C types int and long int can typically handle
only 16 or 32 bit integers.
Your main challenge is to design, implement, and analyze an
extended precision arithmetic data type that can manipulate
large (nonnegative) integers. To make it easier to check your work, we
recommend working with integers represented using familiar decimal (base 10)
notation. (We note that you could achieve superior performance by using a
base that is a power of 2, e.g., 256 or 32,768.)
Your data type will support the following operations:
addition, subtraction, multiplication, division, modular
exponentiation, and comparison. You may use the header file
XP.h.
Part 2 (encryption and decryption).
This part is not required for the warmup. Please see the full description of the assignment for details on Part 2.
Part 3 (analysis).
This part is not required for the warmup. Please see the full description of the assignment for details on Part 3.
This assignment was created by Bob Sedgewick and Kevin Wayne.
Copyright © 2000
Robert Sedgewick