import base64
import string
import collections
import csv
import random
from math import sqrt
import simple_crypto as sc

t1 = """Defeat at the castle seems to have utterly disheartened
      King Arthur.  The ferocity of the French taunting took him completely
      by surprise, and Arthur became convinced that a new strategy
      was required if the quest for the Holy Grail were to be brought
      to a successful conclusion.  Arthur, having consulted his closest
      knights, decided that they should separate, and search for the Grail
      individually.  Now, this is what they did"""
t2 = """Oh king, eh, very nice.  An' how'd you get that, eh?  By
      exploitin' the workers -- by 'angin' on to outdated imperialist dogma
      which perpetuates the economic an' social differences in our society!
      If there's ever going to be any progress"""
t3 = """Listen, lad.  I've built this kingdom up from nothing.  When
      I started here, all there was was swamp.  All the kings said I was
      daft to build a castle in a swamp, but I built it all the same,
      just to show 'em.  It sank into the swamp.  So, I built a second one.
      That sank into the swamp.  So I built a third one.  That burned down,
      fell over, then sank into the swamp.  But the fourth one stayed up.
      An' that's what your gonna get, lad -- the strongest castle in these
      islands."""

text_filter = sc.translator (keep=string.ascii_letters)
t1 = text_filter("".join(t1.split())).lower()
t2 = text_filter("".join(t2.split())).lower()
t3 = text_filter("".join(t3.split())).lower()
k1 = random.choice(string.ascii_lowercase)
k2 = random.choice(string.ascii_lowercase)
k3 = random.choice(string.ascii_lowercase)
print k1,k2,k3
gk1 = sc.freq_decode_char_xor (sc.xor_char (t1, k1))
gk2 = sc.freq_decode_char_xor (sc.xor_char (t2, k2))
gk3 = sc.freq_decode_char_xor (sc.xor_char (t3, k3))
print gk1,gk2,gk3
