1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| from PIL import Image from numpy import array, zeros, uint8 import cv2 import math
def solvePell(n): x = int(math.sqrt(n))
y, z, r = x, 1, x << 1
e1, e2 = 1, 0 f1, f2 = 0, 1 while True: y = r * z - y z = (n - y * y) // z r = (x + y) // z
e1, e2 = e2, e1 + e2 * r f1, f2 = f2, f1 + f2 * r
a, b = f2 * x + e2, f2 if a * a - n * b * b == 1: return a, b
a = 1301149798051259562945444365741194129602596348352064372203373 b = 1175915431138623881271508290982969935822476052419526528443170552123 n = b//a x,y = solvePell(n) kn = 8
image = cv2.imread("encflag_1.jpg") img_gray = image imagearray = array(img_gray) h = len(imagearray) w = len(imagearray[0])
assert 1301149798051259562945444365741194129602596348352064372203373*pow(x, 2) == 1175915431138623881271508290982969935822476052419526528443170552123*pow(y, 2) + 1301149798051259562945444365741194129602596348352064372203373 x1 = round(x/y*0.001, 16) u1 = y*3650/x x2 = round(x/y*0.00101, 16) u2 = y*3675/x x3 = round(x/y*0.00102, 16) u3 = y*3680/x kt = [x1, x2, x3]
temp_image = zeros(shape=[h, w, 3], dtype=uint8) print(len(temp_image)) print(len(temp_image[0])) print(len(temp_image[0][1])) for k in range(0, kn): for i in range(0, h): for j in range(0, w): x1 = u1 * x1 * (1 - x1) x2 = u2 * x2 * (1 - x2) x3 = u3 * x3 * (1 - x3) r1 = int(x1*255) r2 = int(x2*255) r3 = int(x3*255) for t in range(0, 3): temp_image[i][j][t] = (imagearray[i][j][t]-((r1+r2) ^ r3)) % 256 x1 = kt[0] x2 = kt[1] x3 = kt[2]
encflagarray = Image.fromarray(temp_image) encflagarray.show() encflagarray.save("flag.jpg")
|