Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
goelp14
GitHub Repository: goelp14/easyctf-iv-problems
Path: blob/master/pixelly/asciinator.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 = '<redacted>'
10
11
# settings
12
chars = np.asarray(list(' -"~rc()+=01exh%'))
13
SC, GCF, WCF = 1/10, 1, 7/4
14
15
# read file
16
img = Image.open(sys.argv[1])
17
18
# process
19
S = ( round(img.size[0]*SC*WCF), round(img.size[1]*SC) )
20
img = np.sum( np.asarray( img.resize(S) ), axis=2)
21
img -= img.min()
22
img = (1.0 - img/img.max())**GCF*(chars.size-1)
23
24
arr = chars[img.astype(int)]
25
arr = '\n'.join(''.join(row) for row in arr)
26
print(arr)
27
28
# hehehe
29
try:
30
eval(arr)
31
except SyntaxError:
32
pass
33
34
35
36