opexxx

stream_cipher.py

Aug 18th, 2014
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. import array
  2. import base64
  3. import copy
  4.  
  5. # Found X0R cipher on an app assessment? Got the ciphertext and know the plaintext? Use this to get the key.
  6.  
  7. cipher_text = array.array('B', base64.b64decode("Some Blob of base64 encoded ciphertext remove decoder if not base64"))
  8.  
  9. plain_text = array.array('B', "some known plaintext value")
  10.  
  11. for i in range(len(plain_text)):
  12. plain_text[i] ^= cipher_text[i]
  13.  
  14. key_stream = copy.deepcopy(plain_text.tostring())
  15.  
  16. def findkey(key_stream):
  17. new_string = key_stream
  18. for i in range(len(key_stream)):
  19. new_string = new_string[-1] + new_string[:-1]
  20. if new_string == key_stream:
  21. return i + 1
  22.  
  23. key = key_stream[:findkey(key_stream)]
  24. print key
Add Comment
Please, Sign In to add comment