-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypter.py
More file actions
29 lines (27 loc) · 1.09 KB
/
Copy pathcrypter.py
File metadata and controls
29 lines (27 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
from email import message
from RC4 import RC4
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument("-stdin", help="get data from stdin", action='store_true') # TODO description
parser.add_argument("-k", "--key", help="key for algorithm", type=str, required=True)
parser.add_argument("-o", "--output", help="output file", type=argparse.FileType('wb'))
parser.add_argument('-f', '--file', help="input file", type=argparse.FileType('rb'))
parser.add_argument('-m', '--message', help='message for crypt', type=str)
if __name__ == "__main__":
args = parser.parse_args()
dcod = RC4(args.key)
dcod.keySetup()
result = ''
if (args.message):
result = dcod.crypt(args.message)
elif args.stdin:
message = sys.stdin.buffer.read().decode("utf-8")
result = dcod.crypt(message)
elif args.file:
message = args.file.read().decode("utf-8")
result = dcod.crypt(message)
if args.output:
args.output.write(result.encode('utf-8'))
else:
sys.stdout.buffer.write(result.encode('utf-8'))