Skip to content

Instantly share code, notes, and snippets.

@yue82
Last active August 27, 2016 18:23
Show Gist options
  • Save yue82/b20446583093e9afe10584452d9e8a63 to your computer and use it in GitHub Desktop.
Save yue82/b20446583093e9afe10584452d9e8a63 to your computer and use it in GitHub Desktop.
IceCTF OverTheHill writeup
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_{}"
alphadict = {alphabet[n]: n for n in xrange(64)}
ciphertext = "7Nv7}dI9hD9qGmP}CR_5wJDdkj4CKxd45rko1cj51DpHPnNDb__EXDotSRCP8ZCQ"
# m = [[54, 53, 28, 20, 54, 15, 12, 7],
# [32, 14, 24, 5, 63, 12, 50, 52],
# [63, 59, 40, 18, 55, 33, 17, 3],
# [63, 34, 5, 4, 56, 10, 53, 16],
# [35, 43, 45, 53, 12, 42, 35, 37],
# [20, 59, 42, 10, 46, 56, 12, 61],
# [26, 39, 27, 59, 44, 54, 23, 56],
# [32, 31, 56, 47, 31, 2, 29, 41]]
# convert m to modular inverse matrix
# calc in http://planetcalc.com/3324/
im = np.array([[31, 44, 13, 33, 47, 24, 12, 21],
[37, 22, 19, 37, 40, 1, 59, 55],
[45, 59, 63, 4, 27, 63, 20, 50],
[44, 10, 0, 9, 11, 1, 14, 16],
[54, 47, 14, 7, 31, 25, 48, 48],
[39, 2, 56, 48, 38, 27, 48, 34],
[38, 1, 12, 40, 40, 13, 34, 5],
[27, 22, 5, 21, 22, 20, 7, 59]])
flag = ''
for i in xrange(0, 64, 8):
vec = np.array([alphadict[c] for c in ciphertext[i:i+8]])
t = im.dot(vec)
flag += ''.join([alphabet[n%64] for n in list(t.tolist())])
print flag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment