-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbase64decoder.py
More file actions
executable file
·79 lines (55 loc) · 2 KB
/
base64decoder.py
File metadata and controls
executable file
·79 lines (55 loc) · 2 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
#!/usr/bin/python
import argparse
import os
import sys
class printColor:
RED = '\033[91m'
BLUE = '\033[94m'
GREEN = '\033[92m'
END = '\033[0m'
class messages:
NONE_INPUT = "input file path is not defined"
NONE_OUTPUT = "output file path is not defined"
FILE_NOT_FOUND = "File {} was not found"
DONE = "done"
need_print = False
def print_if_needed(string):
if need_print:
print string
def main(inputFile, outputFile):
if inputFile is None:
exit_message = messages.NONE_INPUT
print_if_needed("-i, --input " + printColor.RED +
exit_message + printColor.END)
return exit_message
if outputFile is None:
exit_message = messages.NONE_OUTPUT
print_if_needed("-o, --output " + printColor.RED +
exit_message + printColor.END)
return exit_message
if os.path.exists(inputFile) == False:
exit_message = messages.FILE_NOT_FOUND.format(
os.path.abspath(inputFile))
print_if_needed(printColor.RED +
exit_message + printColor.END)
return exit_message
file = open(inputFile, "r")
base64 = file.read()
result = open(outputFile, "wb")
result.write(base64.decode('base64'))
result.close()
print_if_needed("base64 was " + printColor.GREEN + "successfully" + printColor.END +
" decoded to " + printColor.BLUE +
"{}".format(os.path.abspath(outputFile)) + printColor.END)
return messages.DONE
if __name__ == "__main__":
need_print = True
parser = argparse.ArgumentParser(
description='Decode base64 from input file to output file.')
parser.add_argument('-i', '--input', metavar='',
help='input file path with base64')
parser.add_argument('-o', '--output', metavar='', help='output file path')
args = parser.parse_args()
inputFile = args.input
outputFile = args.output
main(inputFile, outputFile)