
crypted = '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'.decode('hex')


freqs = {
    'a':  8.167,	
    'b':  1.492,	
    'c':  2.782,	
    'd':  4.253,	
    'e':  12.702,	
    'f':  2.228,	
    'g':  2.015,	
    'h':  6.094,	
    'i':  6.966,	
    'j':  0.153,	
    'k':  0.772,	
    'l':  4.025,	
    'm':  2.406,	
    'n':  6.749,	
    'o':  7.507,	
    'p':  1.929,	
    'q':  0.095,	
    'r':  5.987,	
    's':  6.327,	
    't':  9.056,	
    'u':  2.758,	
    'v':  0.978,	
    'w':  2.361,	
    'x':  0.150,	
    'y':  1.974,	
    'z':  0.074,	
    ' ':  8,
}


def xor(strvalue, decrypt):
    result = ''
    for letter in strvalue:
        result += chr(ord(letter) ^ decrypt)
    return result


def text_score(strvalue):
    score = 0
    for letter in strvalue:
        score += freqs.get(letter.lower(), -100)
    return score

def crack_single_xor(crypted):
    return max([xor(crypted, i) for i in range(0, 255)], key=text_score)

if __name__ == "__main__":
    print crack_single_xor(crypted)
