Created
August 27, 2016 18:31
-
-
Save yue82/323ce904038c99168b60e32bc7c4ccac to your computer and use it in GitHub Desktop.
IceCTF InterceptedConversationsPt.2 writeup
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import base64 | |
P = [27, 35, 50, 11, 8, 20, 44, 30, 6, 1, 5, 2, 33, 16, 36, 64, 3, | |
61, 54, 25, 12, 21, 26, 10, 57, 53, 38, 56, 58, 37, 43, 17, 42, | |
47, 4, 14, 7, 46, 34, 19, 23, 40, 63, 18, 45, 60, 13, 15, 22, | |
9, 62, 51, 32, 55, 29, 24, 41, 39, 49, 52, 48, 28, 31, 59] | |
S = [68, 172, 225, 210, 148, 172, 72, 38, 208, 227, 0, 240, 193, | |
67, 122, 108, 252, 57, 174, 197, 83, 236, 16, 226, 133, 94, | |
104, 228, 135, 251, 150, 52, 85, 56, 174, 105, 215, 251, 111, | |
77, 44, 116, 128, 196, 43, 210, 214, 203, 109, 65, 157, 222, | |
93, 74, 209, 50, 11, 172, 247, 111, 80, 143, 70, 89] | |
cipher = base64.b64decode(raw_input().strip()).decode('utf8') | |
plain = [0 for i in range(len(cipher))] | |
for j in range(0, len(cipher), 64): | |
for i in range(64): | |
plain[j + i] = (ord(cipher[j + P[i] - 1]) - S[i]) % 256 | |
print ''.join([chr(p) for p in plain]) |
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
# Python bytecode 3.5 (3350) disassembled from Python 2.7 | |
# Embedded file name: encode.py | |
# Compiled at: 2016-08-08 07:10:09 | |
import random | |
import base64 | |
P = [27, 35, 50, 11, 8, 20, 44, 30, 6, 1, 5, 2, 33, 16, 36, 64, 3, | |
61, 54, 25, 12, 21, 26, 10, 57, 53, 38, 56, 58, 37, 43, 17, 42, | |
47, 4, 14, 7, 46, 34, 19, 23, 40, 63, 18, 45, 60, 13, 15, 22, | |
9, 62, 51, 32, 55, 29, 24, 41, 39, 49, 52, 48, 28, 31, 59] | |
S = [68, 172, 225, 210, 148, 172, 72, 38, 208, 227, 0, 240, 193, | |
67, 122, 108, 252, 57, 174, 197, 83, 236, 16, 226, 133, 94, | |
104, 228, 135, 251, 150, 52, 85, 56, 174, 105, 215, 251, 111, | |
77, 44, 116, 128, 196, 43, 210, 214, 203, 109, 65, 157, 222, | |
93, 74, 209, 50, 11, 172, 247, 111, 80, 143, 70, 89] | |
inp = input() | |
inp += ''.join((chr(random.randint(0, 47)) for _ in range(64 - len(inp) % 64))) | |
ans = ['' for i in range(len(inp))] | |
for j in range(0, len(inp), 64): | |
for i in range(64): | |
ans[j + P[i] - 1] = chr((ord(inp[j + i]) + S[i]) % 256) | |
ans = ''.join(ans) | |
print(base64.b64encode(ans.encode('utf8')).decode('utf8')) | |
# okay decompiling encode.pyc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment