Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import array
- import base64
- import copy
- # Found X0R cipher on an app assessment? Got the ciphertext and know the plaintext? Use this to get the key.
- cipher_text = array.array('B', base64.b64decode("Some Blob of base64 encoded ciphertext remove decoder if not base64"))
- plain_text = array.array('B', "some known plaintext value")
- for i in range(len(plain_text)):
- plain_text[i] ^= cipher_text[i]
- key_stream = copy.deepcopy(plain_text.tostring())
- def findkey(key_stream):
- new_string = key_stream
- for i in range(len(key_stream)):
- new_string = new_string[-1] + new_string[:-1]
- if new_string == key_stream:
- return i + 1
- key = key_stream[:findkey(key_stream)]
- print key
Add Comment
Please, Sign In to add comment