Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 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. ' ': 20
  33. }
  34.  
  35. def score(tmp):
  36. res = 0.0
  37. restxt = ''
  38. for i in tmp:
  39. chari = chr(i).lower()
  40. if chari in scores:
  41. res += scores[chari]
  42. restxt += chr(i)
  43. return (res,restxt)
  44.  
  45.  
  46. def singleByteXorCipher(str1):
  47. tmp1 = binascii.unhexlify(str1)
  48. tmp2 = bytearray(len(tmp1))
  49. maxsc = 0
  50. maxind = 0
  51. max = tmp1
  52. for x in range(0, 256):
  53. for y in range(len(tmp1)):
  54. tmp2[y] = tmp1[y] ^ x
  55. sc = score(tmp2)
  56. if sc[0]>maxsc:
  57. maxsc = sc[0]
  58. max = sc[1]
  59. print(max)
  60.  
  61.  
  62.  
  63. if __name__ == '__main__':
  64. str1 = input().strip()
  65. singleByteXorCipher(str1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement