Created
October 5, 2013 15:16
-
-
Save nk0t/6842167 to your computer and use it in GitHub Desktop.
SU-CTF Crypto200 one Line encoder
This file contains hidden or 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
suctf_enc = lambda text, key: reduce(lambda x, y: (x[0] + str(int(y) ^ int(x[1][0])), x[1][1:] + str(int(x[1][4]) ^ int(x[1][0]))), ''.join(map(lambda x: bin(ord(x))[2:].rjust(8, '0'), text)), ('', key))[0] | |
def split_n(s, n): | |
return [s[i:i+n] for i in range(0, len(s), n)] | |
def enc(text, key): | |
r = '' | |
text = ''.join(map(lambda x: bin(ord(x))[2:].rjust(8, '0'), text)) | |
for (t,s) in zip(text, gen_key(key,len(text))): | |
r += str(int(t) ^ int(s)) | |
return r | |
def dec(text, key): | |
r = '' | |
for (t,s) in zip(text, gen_key(key,len(text))): | |
r += str(int(t) ^ int(s)) | |
rr = '' | |
for c in split_n(r, 8): | |
rr += chr(int(c,2)) | |
return rr | |
def gen_key(s, n): | |
r = [] | |
for i in range(n): | |
r.append(s[0]) | |
s = s[1:] + str(int(s[0]) ^ int(s[4])) | |
return r | |
print enc('hoge', '101010101') | |
print dec('11000010111011100010110110010111', '101010101') | |
encrypted = '11010001011100101100100101011110000110100111111101101001101101111000001010100100011000001001011111011111101000111011111000110111010111100110000000100000101101001000011010111111101010101111011110100011101100001010000010100110001000010100001001110011011011100010011011101110100111011011101011111110001101011101010110001001111101011011011011100000001001110101010101101010111010100001010011010011110001001011010000101011010001111010111111010011011111100100110110111001000011010000111000111100011000110011000111100011010100000100101110110111000111011000001101010111010001111110000010011111101110100110101010001001100100000111010011011011000011100000110101111100111011011101011010111011101110110111011101001010111110011000101111100000111110111010000000100011000100001111000011000010011000111000110011011000011001100000101100101001101011000100101111011100010100101100111100001111010111111011010000000110000110010110010111100111110001101011110000111111000001000110100010111110110001100011001110010101110111010110011110001111010111011001010000010010110100001001000011110100' | |
for key in range(2**9): | |
key = bin(key)[2:].rjust(8, '0') | |
decrypted = dec(encrypted, key) | |
if 'is' in decrypted: | |
print decrypted | |
print 'key:', key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment