Last active
March 26, 2017 16:12
-
-
Save wwong/6a812908a3a06d884ce4b1547c5aeb54 to your computer and use it in GitHub Desktop.
Solution to Comprevawe from VolgaCTF Quals 2017
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
from math import log2, ceil | |
import numpy as np | |
from skimage.io import imread, imsave | |
import pywt | |
def processData(fs, sizeW, sizeH, mode = 'symmetric'): | |
coeffs = fs[:int(sizeW), :int(sizeH)] | |
cA = coeffs[:int(sizeW/2), :int(sizeH/2)] | |
cH = coeffs[int(sizeW/2):, :int(sizeH/2)] | |
cV = coeffs[:int(sizeW/2), int(sizeH/2):] | |
cD = coeffs[int(sizeW/2):, int(sizeH/2):] | |
return pywt.idwt2([cA, (cH, cV, cD)], 'db2', mode) | |
def pad(image): | |
rows, cols = image.shape | |
n = 2**int(max(ceil(log2(rows)), ceil(log2(cols)))) | |
image_padded = np.zeros((n, n), dtype=np.float64) | |
image_padded[n-rows:n, n-cols:n] = image | |
return image_padded | |
if __name__ == '__main__': | |
fs = np.load('./fs.npy') | |
mode = 'smooth' | |
size = 4 | |
threshold = 0.8 | |
sizeH, sizeW = fs.shape | |
while size <= sizeH: | |
newData = pad(processData(fs, size, size, mode=mode)) | |
(newX, newY) = newData.shape | |
fs[:newX, :newY] = newData | |
size *= 2 | |
fs[fs > threshold] = threshold | |
fs[fs <-threshold] = -threshold | |
imsave('./solution.png', fs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment