Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 061e659cfb
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 29 lines (25 sloc) 0.879 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
fh = open('cipher1.txt', 'r')
values = map(lambda x: int(x), fh.read().split(','))

# key is 3 letters from a-z
key_length = 3
valid_chars = [chr(i) for i in xrange(ord('a'), ord('z') + 1)]
clue_words = [' the ', ' and ', ' or ', ' but ', ' in ']

def guess_password(password='', key_length=3):
    if key_length > 0:
        for char in valid_chars:
            guess_password(password + char, key_length - 1)
    else:
        xored = []
        for i in xrange(len(values)):
            xored.append(chr(values[i] ^ ord(password[i % 3])))
        xored_text = ''.join(xored)
        matches = 0
        for clue_word in clue_words:
            if clue_word in xored_text:
                matches += 1
        if matches > 3:
            print password
            print xored_text[:100]
            print sum(map(lambda x: ord(x), xored))
            return

guess_password()
Something went wrong with that request. Please try again.