Advertisement
Guest User

Solved Pirates Challenge

a guest
Jul 31st, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. from Crypto.Cipher import AES
  2. from Crypto.Hash import MD5
  3. import struct
  4. import hashlib
  5.  
  6. class brute:
  7.  
  8. def __init__(self):
  9. self.goal = 'ce975cc4578f4a7005f22ad7182a4d7640a00bd18c6f27c479cebfb1d1778c8b'
  10. self.choices = list('QWERTZUIOPASDFGHJKLYXCVBNM1234567890')
  11. self.index = {'1a' : 0, '1b' : 0, '1c' : 0, '1d' : 0, '2a' : 0, '2b' : 0, '2c' : 0, '2d' : 0}
  12. self.winners = []
  13. self.won = False
  14. self.allDone = False
  15. self.mainLoop()
  16.  
  17. def buildKey1(self, one, two, three, four):
  18. key = '8643-' + one + '120-' + two + 'D' + three + '3-' + four + '893'
  19. return key
  20.  
  21. def buildKey2(self, one, two, three, four):
  22. key = 'E5' + one + 'D-' + two + '722-' + three + '2E8-6' + four + '85'
  23. return key
  24.  
  25. def createCipher(self, key1, key2):
  26. key = key1
  27. blanks = '\0' * 16
  28. h = MD5.new()
  29. h.update(key2)
  30. IV = h.digest() # Initialization vector: discussed later
  31. mode = AES.MODE_CBC
  32. encryptor = AES.new(key, mode, IV=IV)
  33. ciphertext = encryptor.encrypt(blanks)
  34. return ciphertext
  35.  
  36. def checkCorrect(self, ciphertext):
  37. if ciphertext.encode('hex') == self.goal[:32]:
  38. return True
  39. else:
  40. #print ciphertext.encode('hex') + ' failed!'
  41. return False
  42.  
  43. def mainLoop(self):
  44. while not self.won:
  45. #1A
  46. if self.allDone:
  47. print 'Whole index was searched!'
  48. #2B
  49. if self.index['2a'] == 35:
  50. self.index['2a'] = 0
  51. self.index['2b'] = self.index['2b'] + 1
  52. else:
  53. self.index['2a'] = self.index['2a'] + 1
  54. if self.index['2b'] == 35:
  55. self.index['2b'] = 0
  56. self.index['2c'] = self.index['2c'] + 1
  57. if self.index['2c'] == 35:
  58. self.index['2c'] = 0
  59. self.index['2d'] = self.index['2d'] + 1
  60. if self.index['2d'] == 35:
  61. self.index['2d'] = 0
  62. self.allDone = True
  63.  
  64. sha = hashlib.sha1()
  65. sha.update('8643-C120-EDA3-F893')
  66. before = sha.digest()
  67. key1 = before[:16]
  68. key2 = self.buildKey2(self.choices[self.index['2a']], self.choices[self.index['2b']], self.choices[self.index['2c']], self.choices[self.index['2d']])
  69.  
  70. result = self.createCipher(key1, key2)
  71. victory = self.checkCorrect(result)
  72. if victory == True:
  73. self.won = True
  74. self.winners.append('8643-C120-EDA3-F893')
  75. self.winners.append(key2)
  76. else:
  77. #print self.choices[self.index['2a']], self.choices[self.index['2b']], self.choices[self.index['2c']], self.choices[self.index['2d']]
  78. pass
  79.  
  80. print 'Keys found!'
  81. print self.winners
  82.  
  83. brute = brute()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement