SHARE
TWEET

Untitled

a guest Aug 25th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import binascii
  2.     potential_results = []
  3.     character_frequencies = {
  4. 'a': .08167, 'b': .01492, 'c': .02782, 'd': .04253,
  5. 'e': .12702, 'f': .02228, 'g': .02015, 'h': .06094,
  6. 'i': .06094, 'j': .00153, 'k': .00772, 'l': .04025,
  7. 'm': .02406, 'n': .06749, 'o': .07507, 'p': .01929,
  8. 'q': .00095, 'r': .05987, 's': .06327, 't': .09056,
  9. 'u': .02758, 'v': .00978, 'w': .02360, 'x': .00150,
  10. 'y': .01974, 'z': .00074, ' ': .13000
  11. }
  12.     encoded = binascii.unhexlify(enc_str) #hex to byte strings
  13.     for xor_key in range(256):
  14.         decoded = ''.join(chr(b ^ xor_key) for b in encoded)
  15.         if decoded.isprintable():
  16.             score = sum([character_frequencies.get(byte, 0) for byte in decoded], [0])
  17.             data = {'message':decoded, 'score':score, 'key':xor_key}
  18.             potential_results.append(data)
  19. best_score = sorted(potential_results, key=lambda x: x['score'], reverse=True)
  20.     for item in best_score:
  21.         print("{}: {}".format(item.title(), best_score[item]))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top