-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExplosiveEnc.py
More file actions
49 lines (35 loc) · 996 Bytes
/
ExplosiveEnc.py
File metadata and controls
49 lines (35 loc) · 996 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
43
44
45
46
47
__author__ = 'yanivb'
import base64
def decode_conf(value):
"""
Decode an explosive message
"""
if not value:
return None
if "@" in value:
try:
return "".join(chr(int(c)) for c in value.rstrip()[:-1].split("@"))
except Exception as ex:
print "Failed to decode value %s: %s" % ex
return None
return value
def encode_conf(value):
"""
Encode an explosive message
"""
if not value:
return None
try:
return "".join(str(ord(c)) + "@" for c in value)
return a
except Exception as ex:
print "Failed to encode value %s: %s" % ex
return None
def decode_comm(value):
if not value or not value.startswith("=="):
raise ValueError("Message is not encoded")
return base64.decodestring(value[::-1])[::-1]
def encode_comm(value):
if not value:
return None
return base64.encodestring(value[::-1])[::-1].replace('\n','')