-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_64.py
35 lines (24 loc) · 864 Bytes
/
base_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
34
35
import argparse
import base64
def encode(text)-> str:
enc_text = base64.b64encode(bytes(u'{}'.format(text), "utf-8"))
return enc_text
def decode(coded_string)-> str:
decoded_text = base64.b64decode(coded_string)
return decoded_text
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--text", type=str, required=True, help="text to be encoded and decoded")
parser.add_argument("--decode", help="text to be decoded", action="store_true")
parser.add_argument("--encode", help="choose whether to encode given text", action="store_true")
args = parser.parse_args()
if args.encode:
etext = encode(args.text)
print(etext.decode('UTF-8'))
elif args.decode:
decoded_text = decode(args.text)
print(decoded_text.decode('UTF-8'))
else:
print("No encode/decode option specified. Exiting...")
if __name__ == '__main__':
main()