-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path64.py
33 lines (29 loc) · 864 Bytes
/
64.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
'''Usage:
64.py [--encode TEXT]
64.py [--decode TEXT]
64.py -h --help
Options:
-e --encode Encode text with Base64.
-d --decode Decode Base64 text.
'''
import docopt
import base64
def B64(args):
text = bytes(args['TEXT'], 'utf-8')
if(args['--encode'] == True):
output = base64.b64encode(text)
output = bytes.decode(output, 'utf-8')
if(args['--decode'] == True):
output = base64.b64decode(text)
output = bytes.decode(output, 'utf-8')
return output
if __name__ == "__main__":
try:
args = docopt.docopt(__doc__)
data = B64(args)
if(args['--encode'] == True):
print('Encoded Text: \n', data)
if(args['--decode'] == True):
print('Decoded Text: \n', data)
except docopt.DocoptExit as e:
print(e.usage)