Enter the text you want to decode in the first line of the next cell. The output will be one big block of text that follows the uppercase convention for encrypted text.


In [1]:
cipherText = "GUVF VF GUR RAPELCGRQ GRKG LBH JNAG GB QRPBQR"
smashText = ""
for line in cipherText:
	smashText = smashText + line.upper()
print smashText


GUVF VF GUR RAPELCGRQ GRKG LBH JNAG GB QRPBQR

Make sure to evaluate the cell above before running the cell below. The output of the cell below is the relative frequency of each letter in the cipher alphabet.


In [2]:
cipherAlphabet = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

totalChars = float(smashText.count(""))
countList = [(letter,float(smashText.count(letter))/totalChars*100) for letter in cipherAlphabet]
sortedValues = sorted(countList, key=lambda freq: freq[1], reverse = True)
for i in sortedValues:
	print i


('G', 15.217391304347828)
('R', 13.043478260869565)
('B', 6.521739130434782)
('Q', 6.521739130434782)
('A', 4.3478260869565215)
('F', 4.3478260869565215)
('L', 4.3478260869565215)
('P', 4.3478260869565215)
('U', 4.3478260869565215)
('V', 4.3478260869565215)
('C', 2.1739130434782608)
('E', 2.1739130434782608)
('H', 2.1739130434782608)
('J', 2.1739130434782608)
('K', 2.1739130434782608)
('N', 2.1739130434782608)
('D', 0.0)
('I', 0.0)
('M', 0.0)
('O', 0.0)
('S', 0.0)
('T', 0.0)
('W', 0.0)
('X', 0.0)
('Y', 0.0)
('Z', 0.0)

The following is a frequency table for the english language:

Based on this information, we might expect G and R to represent e and t in some order. Based on positions in the text, we guess that G : t and R : e.


In [3]:
plaintextAlphabet = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
plaintextAlphabet = ['A','B','C','D','E','F','t','H','I','J','K','L','M','N','O','P','Q','e','S','T','U','V','W','X','Y','Z']

In [4]:
keyDict = dict(zip(cipherAlphabet,plaintextAlphabet))
plainText = smashText

for i, j in keyDict.iteritems():
    plainText = plainText.replace(i, j)
    
print plainText


tUVF VF tUe eAPELCteQ teKt LBH JNAt tB QePBQe

We can make some educated guesses from here. Note that we won't be guaranteed a unique solution for our plaintext alphabet because some of the characters in the cipher alphabet are never used. But we can make enough guesses to get enough of the plaintext alphabet to decrypt the message.


In [5]:
plaintextAlphabet = ['n','o','p','D','r','s','t','u','I','w','x','y','M','a','O','c','d','e','S','T','h','i','W','X','Y','Z']

In [6]:
keyDict = dict(zip(cipherAlphabet,plaintextAlphabet))
plainText = smashText

for i, j in keyDict.iteritems():
    plainText = plainText.replace(i, j)
    
print plainText


this is the encrypted text you want to decode