Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
goelp14
GitHub Repository: goelp14/easyctf-iv-problems
Path: blob/master/pixelly/src/run.py
650 views
1
#!/usr/bin/env python3
2
# Modified from https://gist.github.com/cdiener/10491632
3
4
import sys
5
from PIL import Image
6
import numpy as np
7
8
# it's me flage!
9
flag = 'easyctf{wish_thi5_fl@g_was_1n_ASCII_@rt_t0o!}'
10
11
# settings
12
chars = np.asarray(list(' -"~rc()+=01exh%'))
13
SC, GCF, WCF = 1/10, 1, 7/4
14
15
# uncomment this for haxxor
16
'''
17
import io
18
with open(sys.argv[1], 'rb') as f:
19
s = f.read()
20
try:
21
eval(s)
22
except (ValueError, SyntaxError):
23
pass
24
'''
25
26
# read file
27
img = Image.open(sys.argv[1])
28
29
# process
30
S = ( round(img.size[0]*SC*WCF), round(img.size[1]*SC) )
31
img = np.sum( np.asarray( img.resize(S) ), axis=2)
32
img -= img.min()
33
img = (1.0 - img/img.max())**GCF*(chars.size-1)
34
35
arr = chars[img.astype(int)]
36
arr = '\n'.join(''.join(row) for row in arr)
37
print(arr)
38
39
# hehehe
40
try:
41
eval(arr)
42
except SyntaxError:
43
pass
44
45
46
47