Created
February 10, 2017 20:38
-
-
Save unicornsasfuel/f3a59a204441e333855a7ae71839a61e to your computer and use it in GitHub Desktop.
Custom stream cipher CTF challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
KEY = #NAH | |
FLAG = #NAH | |
message = 'Hello LOLCTF! Can you beat my super-leet stream cipher? If you can, the flag is: ' + FLAG | |
def sxor(s1, s2): | |
return ''.join([chr(ord(c1) ^ ord(c2)) for c1, c2 in zip(s1, s2)]) | |
def sha1prng(key, length): | |
num_hashes = (length / 20) + 1 | |
state = key | |
output = '' | |
for i in range(num_hashes): | |
hasher = hashlib.sha1() | |
hasher.update(state) | |
state = hasher.digest() | |
output += state | |
return output | |
def my_stream_cipher(key, data): | |
''' Encrypt / decrypt function for my custom stream cipher ''' | |
return sxor(data, sha1prng(key, len(data))) | |
output = open('output.txt', 'w') | |
output.write(my_stream_cipher(KEY, message).encode('hex')) | |
output.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13add529091b5a5df1a8a10766f711a3f8e7d1613e6d1d1b1b383039acd9ded2748e80a957a12fa8b5ecd5f741dcf6c436de3245c0e0e956771850ccee3bc2002c6bd3bc924c49991285614a874c28d0ba36e9e0d0fb5b9b5bb48cec11724030315eea7ab8d4670e3e3f95f9d6f054a5800f0d4fef3e5cb182c02364ae352ca6d9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment