# CSC 15 RSA Decryption Lab # The Rivest-Shamir-Adleman (RSA) public key encryption algorithm works # as follows: two very large prime numbers p and q are chosen and # kept secret. Let n = p*q (the idea is that it's hard to figure out # what q and p are given n). Two more numbers, d and e, are picked so # that (e*d) % ((p-1)*(q-1)) == 1. The pair (n,e) is called the # public key or encryption key, and is used by everybody to encrypt # messages. The private key consists of the number d, which is # kept secret. A message can be represented as a number m between 0 and # n-1. To encrypt the message, compute m to the eth power mod n, # or m**e % n. To decrypt the "cipher" message c, we use c**d%n. That is, # if c = m**e%n, then c**d%n will give us the original message m. # In practice the prime numbers used for encryption are very large, with # several hundred digits. But smaller numbers are enough to illustrate # the concept. For example, we can pick the two primes to be p,q = 47,59 # and e = 17, d = 157, and n = p*q (2773). We can encode text messages # character by character using their ascii values. For example, # "hello" has the corresponding list/array of (unencrypted) ascii values: # [104, 101, 108, 108, 111] ## Here is the function that encodes a single ascii value m, with ## "public key" e and n: def encode1(m,e,n): return m**e % n ## Now here is a function that encodes an array of ascii values: def encodeArray(M,e,n): C = len(M)*[0] # create array of same size as M, initial values all 0 i = 0 while i