-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangeling
More file actions
executable file
·42 lines (31 loc) · 812 Bytes
/
changeling
File metadata and controls
executable file
·42 lines (31 loc) · 812 Bytes
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
#!/usr/bin/env python3
import shapescript, sys
def error(adjective):
print('This shape is %s.' % adjective)
exit(1)
try:
changeling = open(sys.argv[1]).read().split('\n')
except IndexError:
print('Syntax: %s source-file' % argv[0], file = sys.stderr)
exit(1)
if changeling.pop() != '' or any(len(line) != len(changeling) for line in changeling):
error('unpleasant')
source = ''
for line in changeling:
if not line or min(line) < ' ' or max(line) > '~':
error('unpleasant')
accumulator = 0
for char in line + '\n':
value = ord(char)
try:
source += chr(value ^ (accumulator >> 1))
except:
error('unpleasant')
accumulator += value - 32
try:
for item in shapescript.interpret(source):
print(item, end = '')
except SyntaxError:
error('unpurposed')
except:
error('inadequate')