-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
45 lines (34 loc) · 1.52 KB
/
main.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
36
37
38
39
40
41
42
43
44
45
import inqcipher
import sys
import os
import json
from argparse import ArgumentParser
if __name__ == '__main__':
if not os.path.isfile('config.json'):
print('Missing config file!')
raise SystemExit
with open('config.json', 'r') as raw:
config = json.loads(raw.read())
chars = config['chars']
levels = config['levels']
parser = ArgumentParser()
subparsers = parser.add_subparsers(title='Available commands.', dest='command')
# Encrypt options
encrypt = subparsers.add_parser('encrypt', description='Encrypt a plain text')
encrypt.add_argument('plain', help='Plain text to encrypt.')
encrypt.add_argument('key', help='Key to encrypt.')
# Decrypt options
decrypt = subparsers.add_parser('decrypt', description='Decrypt a ciphered message.')
decrypt.add_argument('plain', help='Ciphered message to decrypt.')
decrypt.add_argument('key', help='Key to decrypt.')
# Generate options
generate = subparsers.add_parser('generate', description='Generate a random key.')
args = parser.parse_args()
if args.command == 'encrypt':
wheel = inqcipher.decrypt_key(chars, args.encrypt.key, levels)
print(inqcipher.encrypt(args.encrypt.plain, wheel, chars))
if args.command == 'decrypt':
wheel = inqcipher.decrypt_key(chars, args.key, levels)
print(inqcipher.decrypt(args.decrypt, wheel, chars))
if args.command == 'generate':
print(inqcipher.generate_key(chars, inqcipher.generate_wheel(chars, levels)))