Last active
October 30, 2022 19:17
-
-
Save Opposite34/97645762884abc536c9929ba14008187 to your computer and use it in GitHub Desktop.
BlueHensCTF2022 - PurQRatory Solve Scripts
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
| #edited: knew after writing this that pdfimages from poppler.utils does the same job but easier... | |
| from pdf2image import convert_from_path | |
| #doing this in batches so it doesn't killed itself (+ forlooping broke somehow soooo yea) | |
| dpi = 300 | |
| path = "./PurQRatory.pdf" | |
| pages = convert_from_path(path, dpi=500, output_folder="",last_page=26) | |
| pg_no = 1 | |
| for page in pages: | |
| page.save(f'./converted/qr{pg_no}.jpg', 'JPEG') | |
| pg_no += 1 | |
| pages = convert_from_path(path, dpi=dpi, first_page=27, last_page=52) | |
| for page in pages: | |
| page.save(f'./converted/qr{pg_no}.jpg', 'JPEG') | |
| pg_no += 1 | |
| pages = convert_from_path(path, dpi=dpi, first_page=53, last_page=78) | |
| for page in pages: | |
| page.save(f'./converted/qr{pg_no}.jpg', 'JPEG') | |
| pg_no += 1 | |
| pages = convert_from_path(path, dpi=dpi, first_page=79, last_page=107) | |
| for page in pages: | |
| page.save(f'./converted/qr{pg_no}.jpg', 'JPEG') | |
| pg_no += 1 |
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
| from PIL import Image | |
| qr_count = 0 | |
| for pg in range(1,108): | |
| path = f"./converted/qr{pg}.jpg" | |
| im = Image.open(path) | |
| width, height = im.size | |
| padding = 320 | |
| bot = height-1025 | |
| top = height/3 + 200 | |
| for i in range(4): | |
| if i == 0: | |
| im_cropped = im.crop((padding,padding,width/2,top)) | |
| elif i == 1: | |
| im_cropped = im.crop((width/2,padding,width-padding,top)) | |
| elif i == 2: | |
| im_cropped = im.crop((padding,top,width/2,bot)) | |
| else: | |
| im_cropped = im.crop((width/2,top,width-padding,bot)) | |
| qr_count += 1 | |
| wc,hc = im_cropped.size | |
| res_im = im_cropped.resize((int(wc/5),int(hc/5)),resample=Image.Resampling.NEAREST) | |
| res_im.save(f"./converted/final/{qr_count}.jpg") |
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 cv2 | |
| path = "./converted/final" | |
| f = open('val.txt', 'w') | |
| for i in range(1, 428): | |
| img=cv2.imread(f"{path}/{i}.jpg") | |
| det=cv2.QRCodeDetector() | |
| val, pts, st_code=det.detectAndDecode(img) | |
| f.write(val+'\n') | |
| f.close() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
part1 -> pdf to image
part2 -> each of the QRs in the image into it's separated thing (+ resizing so the reader works better)
part3 -> qrcode reader in opencv, was able to read all but one qrcode