Last active
December 31, 2023 14:11
-
-
Save lbr77/498bb5e9ead02e8f79862a0162bda5a8 to your computer and use it in GitHub Desktop.
Game
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
import base64 as b64 | |
def bintotext(ress, count=7): | |
res = "" | |
for i in range(0, len(ress), count): | |
res += chr(int(ress[i : i + count], 2)) | |
return res | |
import cv2 as cv | |
import numpy as np | |
img = cv.imread("dct.jpg", cv.IMREAD_GRAYSCALE) | |
height, width = img.shape | |
blocks = [] | |
for i in range(0, height, 8): | |
for j in range(0, width, 8): | |
block = img[i : i + 8, j : j + 8] | |
dct = cv.dct(np.float32(block)) | |
blocks.append(dct) | |
result = "" | |
for block in blocks: | |
if block[3, 0] > block[1, 2]: | |
result += "1" | |
else: | |
result += "0" | |
print(bintotext(result, 8)) |
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
fl = "It's hard to write flag to DCT.flag{64499398}" | |
fl = "".join([bin(ord(i))[2:].zfill(8) for i in fl]) | |
import cv2 as cv | |
import numpy as np | |
r = cv.cvtColor(cv.imread("use2.jpg"), cv.COLOR_BGR2GRAY) | |
height, width = r.shape | |
idx = 0 | |
for i in range(0, height, 8): | |
for j in range(0, width, 8): | |
if idx >= len(fl): | |
break | |
block = r[i : i + 8, j : j + 8] | |
dct = cv.dct(np.float32(block)) | |
dct[3, 0] = dct[1, 2] + 10 if fl[idx] == "1" else dct[1, 2] - 10 | |
r[i : i + 8, j : j + 8] = np.uint8(cv.idct(dct)) | |
idx += 1 | |
# cv.save("dct.jpg", r) | |
cv.imwrite("dct.jpg", r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment