-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathencode.py
More file actions
80 lines (68 loc) · 3.79 KB
/
encode.py
File metadata and controls
80 lines (68 loc) · 3.79 KB
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
#!/usr/bin/env python
# base64 - 32 and 12 runs better with python2 (just use python)
# base85 and ascii85 encoding required python3 (run the script using python3 encode.py --...... )
# if you have plans to use base64/32/16 with Python3 you need to use technique of encode / decode since you need to work with bytes, not plain str (strings)
import codecs, sys, base64
#myline = b'one'
if len(sys.argv) > 1:
if sys.argv[1]=="--base64": #this particulary checks arg1.Raises an error if no argv[1] exists.
for line in sys.stdin:
print(base64.b64encode(line))
if sys.argv[1]=="--base32": #this particulary checks arg1.Raises an error if no argv[1] exists.
for line in sys.stdin:
print(base64.b32encode(line))
if sys.argv[1]=="--base16": #this particulary checks arg1.Raises an error if no argv[1] exists.
for line in sys.stdin:
print(base64.b16encode(line))
if sys.argv[1]=="--base85": #this particulary checks arg1.Raises an error if no argv[1] exists.
for line in sys.stdin:
s = line
b = s.encode("UTF-8") # Encoding the string into bytes
e = base64.b85encode(b) # Base85 Encode the bytes
s1 = e.decode("UTF-8") # Decoding the Base85 bytes to string
print(s1) # Printing Base85 encoded string
if sys.argv[1]=="--ascii85": #this particulary checks arg1.Raises an error if no argv[1] exists.
for line in sys.stdin:
s = line
b = s.encode("UTF-8") # Encoding the string into bytes
e = base64.a85encode(b) # Base85 Encode the bytes
s1 = e.decode("UTF-8") # Decoding the Base85 bytes to string
print(s1) # Printing Base85 encoded string
#Decode Functions-----------------------------------------------------------------------------------------#
if sys.argv[1]=="--decodebase64": #this particulary checks arg1.Raises an error if no argv[1] exists.
for line in sys.stdin:
print("b64decode")
print(base64.b64decode(line))
print("")
print("standard_b64decode")
print(base64.standard_b64decode(line))
print("")
print("urlsafe_b64decode")
print(base64.urlsafe_b64decode(line))
if sys.argv[1]=="--decodebase32": #this particulary checks arg1.Raises an error if no argv[1] exists.
for line in sys.stdin:
print(base64.b32decode(line))
if sys.argv[1]=="--decodebase16": #this particulary checks arg1.Raises an error if no argv[1] exists.
for line in sys.stdin:
print(base64.b16decode(line))
if sys.argv[1]=="--decodebase85": #this particulary checks arg1.Raises an error if no argv[1] exists.
for line in sys.stdin:
s1 = line
b1 = s1.encode("UTF-8") # Encoding the Base85 encoded string into bytes
d = base64.b85decode(b1) # Decoding the Base85 bytes
s2 = d.decode("UTF-8") # Decoding the bytes to string
print(s2)
if sys.argv[1]=="--decodeascii85": #this particulary checks arg1.Raises an error if no argv[1] exists.
for line in sys.stdin:
s1 = line
b1 = s1.encode("UTF-8") # Encoding the Base85 encoded string into bytes
d = base64.a85decode(b1) # Decoding the Base85 bytes
s2 = d.decode("UTF-8") # Decoding the bytes to string
print(s2)
if sys.argv[1]=="--help": #Raises an error if no argv[1] exists.
print('Usage: --base64 --base32 --base16 --base85 --ascii85 --decodebase64 --decodebase32 --decodebase16 --decodebase85 --decodeascii85')
#exit
#else:
# print('Encoding Function')
# for line in sys.stdin: #default operation - encodes the input (pipe)
# print(codecs.encode(line, 'rot13'))