Newer
Older
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
from snipper.fix_s import get_s #!s
from snipper.block_parsing import block_split
import textwrap
import numpy as np
# Implement a sieve here.
def primes_sieve(limit):
limitn = limit+1 #!b
primes = range(2, limitn)
for i in primes:
factors = list(range(i, limitn, i))
for f in factors[1:]:
if f in primes:
primes.remove(f)
return primes #!b
#!s
def obscure(blk, fun):
blok = block_split(blk, "#!b")
lines2 = blok['first'] + fun(blok['block']) + blok['last']
s = '\n'.join(lines2)
print(s)
return s
# driver program
if __name__ == '__main__':
with open(__file__, 'r') as f:
s = f.read().splitlines()
blk = get_s(s)['']
def cmnt(lines):
whitespace = " " * (len(lines[0]) - len(lines[0].lstrip()))
lines = textwrap.dedent("\n".join(lines)).splitlines()
lines = ["# " + l for l in lines]
return lines, whitespace
def f1(lines):
lines, whitespace = cmnt(lines)
lines = [lines[i] for i in np.random.permutation(len(lines))]
lines = textwrap.indent("\n".join(lines), whitespace).splitlines()
return lines
obscure(blk, f1)
def f2(lines):
lines, whitespace = cmnt(lines)
kp = """#'"[](){},.+-012345679:="""
l2 = []
for line in lines:
line2 = []
for w in line.split(' '):
if w in ['', 'return', 'if', 'else' '=', '#', "for", "in"]:
line2.append(w)
else:
w2 = "".join( [ (t if t in kp else '?') for t in w] )
line2.append(w2)
l2.append(" ".join(line2))
lines = l2
lines = textwrap.indent("\n".join(lines), whitespace).splitlines()
return lines
obscure(blk, f2)