-
Notifications
You must be signed in to change notification settings - Fork 0
/
a04.py
94 lines (78 loc) · 2.68 KB
/
a04.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# License: The MIT License
# Project: https://github.com/sigv/a04-xchat
# Modify the following line to represent the location of the Eyesgulis project
projectpath = '/home/user/a04-xchat'
__module_name__ = 'a04'
__module_version__ = '0.1.0'
__module_description__ = 'Provides simple a04 decoding and encoding support on the run'
import xchat
import os
os.sys.path.append(projectpath + '/backend')
encode = None
decode = None
try:
from encoder import encode
from decoder import decode
except ImportError:
print('Unable to import the main Eyesgulis project. Did you set the path?')
def command_cb(word, word_eol, userdata):
msg = None
key = None
hashsys = 'sha1'
mutate = False
mutatekey = ''
say = False
sayloud = False
if len(word) < 2:
xchat.prnt('You must specify whether you want to encode or decode: /a04 encode|decode')
return xchat.EAT_ALL
act = word[1]
if act != 'encode' and act != 'decode':
xchat.prnt('You must specify whether you want to encode or decode: /a04 encode|decode')
return xchat.EAT_ALL
for cmd in ' '.join(word[2:]).split('--'):
if cmd.startswith('msg '):
msg = cmd[4:].strip()
if cmd.startswith('key '):
key = cmd[4:].strip()
if cmd.startswith('hash '):
hashsys = cmd[5:].strip()
if cmd.strip() == 'mutate':
mutate = True
if cmd.startswith('mutatekey '):
mutatekey = cmd[10:].strip()
if cmd.strip() == 'say':
say = True
if cmd.strip() == 'loud':
sayloud = True
if msg is None:
xchat.prnt('You must specify a message to ' + act + ': /a04 ' + act + ' --msg <msg>')
return xchat.EAT_ALL
if key is None:
xchat.prnt('You must specify a key to ' + act + ': /a04 ' + act + ' --key <key>')
return xchat.EAT_ALL
if act == 'encode':
encoded = encode(msg, key, hashsys, False, mutate)
out = ' '.join(encoded[0])
if filter(None, encoded[1]) != []:
out += ' (mutation key: ' + ':'.join(encoded[1]) + ')'
if say:
if sayloud:
xchat.get_context().command('say ' + hashsys + ' | ' + key + ' | ' + out)
else:
xchat.get_context().command('say ' + out)
else:
xchat.prnt('encoded message: ' + out)
if act == 'decode':
decoded = decode(msg, key, hashsys, False, False, mutate, mutatekey)
if decoded == '':
xchat.prnt('the decoder couldn\'t decode anything for the given message')
else:
if say:
xchat.get_context().command('say decoded message: ' + decoded);
else:
xchat.prnt('decoded message: ' + decoded)
return xchat.EAT_ALL
if encode is not None and decode is not None:
xchat.hook_command('a04', command_cb, help='Usage: a04 encode|decode [--say [--loud]] --msg <msg> --key <key> [--hash <hash>], prints (or, if instructed to, says) the resulting message')
print('a04 has been loaded successfully')