Skip to content

Instantly share code, notes, and snippets.



Last active Mar 26, 2017
What would you like to do?
Solution to Comprevawe from VolgaCTF Quals 2017
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from math import log2, ceil
import numpy as np
from 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
You can’t perform that action at this time.