from pwn import *
import string

def score(s):
  scores = {
    '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.360,
    'x': 0.150,
    'y': 1.974,
    'z': 0.074
  }

  return sum([scores[c.lower()] if c.isalpha() else (0 if c.isdigit() or c == ' ' else -9999) for c in s])

def decrypt_single_xor(c):
  ds = []
  for i in range(0, 0x100):
    d = xor(chr(i), c)
    ds.append((score(d), i, d))

  ds.sort(key=lambda x: x[0], reverse=True)
  return ds

if __name__ == '__main__':
  c = '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'.decode('hex')
  print '\n'.join([d[2] for d in decrypt_single_xor(c)[:1]])
021add96057c422631ff028a9013683ed16b363d
from pwn import *
import string

def score(s):
  scores = {
    '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.360,
    'x': 0.150,
    'y': 1.974,
    'z': 0.074
  }

  return sum([scores[c.lower()] if c.isalpha() else (0 if c.isdigit() or c == ' ' else -9999) for c in s])

def decrypt_single_xor(c):
  ds = []
  for i in range(0, 0x100):
    d = xor(chr(i), c)
    ds.append((score(d), i, d))

  ds.sort(key=lambda x: x[0], reverse=True)
  return ds

if __name__ == '__main__':
  c = '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'.decode('hex')
  print '\n'.join([d[2] for d in decrypt_single_xor(c)[:1]])