Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import binascii
  2. import collections
  3.  
  4.  
  5. scores = {
  6. 'a': 8.167,
  7. 'b': 1.492,
  8. 'c': 2.782,
  9. 'd': 4.253,
  10. 'e': 12.702,
  11. 'f': 2.228,
  12. 'g': 2.015,
  13. 'h': 6.094,
  14. 'i': 6.966,
  15. 'j': 0.153,
  16. 'k': 0.772,
  17. 'l': 4.025,
  18. 'm': 2.406,
  19. 'n': 6.749,
  20. 'o': 7.507,
  21. 'p': 1.929,
  22. 'q': 0.095,
  23. 'r': 5.987,
  24. 's': 6.327,
  25. 't': 9.056,
  26. 'u': 2.758,
  27. 'v': 0.978,
  28. 'w': 2.360,
  29. 'x': 0.150,
  30. 'y': 1.974,
  31. 'z': 0.074,
  32. ' ': 19
  33. }
  34.  
  35. def score(tmp):
  36. res = 0.0
  37. for i in tmp:
  38. chari = chr(i).lower()
  39. if chari in scores:
  40. res += scores[chari]
  41. return res
  42.  
  43.  
  44. def singleByteXorCipher(str1):
  45. tmp1 = binascii.unhexlify(str1)
  46. tmp2 = bytearray(len(tmp1))
  47. maxsc = 0
  48. maxind = 0
  49. max = tmp1
  50. for x in range(0, 256):
  51. for y in range(len(tmp1)):
  52. tmp2[y] = tmp1[y] ^ x
  53. sc = score(tmp2)
  54. if sc>maxsc:
  55. maxsc= sc
  56. max = tmp2
  57. print (binascii.hexlify(max).decode('ascii'))
  58.  
  59.  
  60.  
  61. if __name__ == '__main__':
  62. str1 = input().strip()
  63. singleByteXorCipher(str1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement