forked from barbosa46/Python-Crypto-Details
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase64_encode_decode.py
More file actions
41 lines (33 loc) · 1.09 KB
/
Copy pathbase64_encode_decode.py
File metadata and controls
41 lines (33 loc) · 1.09 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
import base64
import sys
class base64_encode_decode:
def encode(data):
return base64.b64encode(data)
def decode(data):
return base64.b64decode(data)
def encode_file(input_path, output_path):
with open(input_path, "rb") as f_in:
data = f_in.read()
encoded = base64.b64encode(data)
with open(output_path, "wb") as f_out:
f_out.write(encoded)
def decode_file(input_path, output_path):
with open(input_path, "rb") as f_in:
data = f_in.read()
decoded = base64.b64decode(data)
with open(output_path, "wb") as f_out:
f_out.write(decoded)
if __name__ == "__main__":
if len(sys.argv) != 4:
print("Uso: python base64_encode_decode.py <encode|decode> <input_file> <output_file>")
sys.exit(1)
mode = sys.argv[1]
input_file = sys.argv[2]
output_file = sys.argv[3]
if mode == "encode":
encode_file(input_file, output_file)
elif mode == "decode":
decode_file(input_file, output_file)
else:
print("Modo inválido. Use 'encode' ou 'decode'.")
sys.exit(1)