### Problem Set #1

#### Due: Feb 1st, 2005 at 11am

Remember, your homework MUST be submitted in LaTeX!

Problem 1. (Difficulty: 4) The ciphertexts below were encrypted with a blockcipher with domain and range {a,...,z}. The key is a random permutation of the domain (and there are too many keys for exhaustive key-search to make sense). Please write a python program that deciphers these texts. Note: each ciphertext has a different key, so attack them separately. All are English text.

You may use any techniques you like. Frequency analysis, index of coincidence, stats on diphthongs, triphthongs, start letters, end letters, double-letters, etc.

Your program should recover the plaintext with 100% accuracy with no human intervention. To achieve this, use a list of English words, and go with the substitution that yields a sufficiently-high number of English words in the text. There is a word list you might use.

Here is the program used to generate the ciphertexts:

```#!/usr/local/bin/python

def perm(s, key):
ct = ''
a = ord('a')
for c in s.lower():
if 'a' <= c <= 'z':
ct += chr(key[ord(c)-a]+a)
else:
ct += c
return ct

p1 = """
Sample plaintext 1
"""

p2 = "Sample 2"

import random

key = range(26)
random.shuffle(key)

for pt in (p1,p2):
ct = perm(pt, key)
print ct
```

And here are the ciphertexts:

0. wqp dyee akifkj fq quy qd fgy ieollki xepunycl. fgy jqlf dojqpl kl "uyayc myf kuaqeayn ku o eoun soc ku olko." xpf quew lekmgfew eyll syee ruqsu kl fgkl: "uyayc mq ku omokulf o lkikekou sgyu nyofg kl qu fgy ekuy."

1. hsen owsj sud, zq't erkvzkwztj; hsen owsj qas, zq't wdtdkwhp.

2. y zyufa cbhvxa cw rna oawr uahcqa ivu nyqqcbaww c alau nayuj vi.

3. jk cwjv sqzhe, kqcwjkp jv lozcmjk txc eomcw mke cmfov.

4. kqozy kfq vzzx hq rz zmius kahf ozy sulx uorahaqy.

5. oltp wsfy qsp wfypdsz ef, ethfy ef ypdsqmfd.

6. ugsxqxai xi qez wzyqsz pvq gj wzqqxyw fgqzi jvgl qez uggv pyh aplupxwy jdyhi jvgl qez vxae om uvglxixyw qg uvgqzaq zpae jvgl qez gqezv.

7. tfble snowpnywzv, vnf lgoykwpz vnf. tfble skvvtfwzv, wp'z utzp prl kookzwpl.

8. ugcvivyl fmce vi kzie hcdji emj gjhjhogcyaj wjcg.

9. brwqhlfkw hjk qibwk qicedw zbg wkk mike zbg qhsk zbgj kzkw buu zbgj dbhfw.

10. rka pbrgsgxr rkgjnx rkgx gx rka zaxr pt uii ypfiex. rka baxxgsgxr taufx rkgx gx rfda.

Turn in your program along with a program-run that deciphers each of the ciphertexts above.

Problem 2. (Difficulty: 1)

Implement, once again in python, functions to perform the following tasks:

• gcd(a, b) finds the gcd of a and b. Use Euclid's algorithm.
• modx(base,exp,mod) performs the modular exponentiation of the integer base to the power exp modulo the integer mod. Using the repeated squaring algorithm described in class.
• pseud(base, start) finds the first integer starting at the positive integer start that passes the Fermat test with base base.
• inv(a, n) finds the inverse of a modulo n. Use the extended Euclidean algorithm, and return -1 if a has no inverse modulo n.
Turn in your code for each function above.

Problem 3. (Difficulty: 1)