|
1 |
| -from .crypt import encrypt, decrypt |
2 |
| -from .utils import write_file |
3 |
| -from .crack import bruteforce |
| 1 | +from .handlers import bruteforce_handler, decrypt_handler, encrypt_handler |
4 | 2 | import argparse
|
5 | 3 |
|
6 | 4 | parser = argparse.ArgumentParser(
|
|
31 | 29 |
|
32 | 30 |
|
33 | 31 | def handle_args():
|
34 |
| - # If key isn't in the args, |
35 |
| - if not args.key and (args.encrypt or args.decrypt): |
36 |
| - raise NameError("Key is not defined") |
37 |
| - # If the bruteforce flag used |
38 |
| - elif args.brute: |
39 |
| - c_value = ' '.join(args.brute) |
40 |
| - cracked = [] |
41 |
| - if args.sourceFile: |
42 |
| - f = open(c_value, 'r').read() |
43 |
| - cracked = bruteforce(f) |
| 32 | + try: |
| 33 | + # If key isn't in the args, |
| 34 | + if not args.key and (args.encrypt or args.decrypt): |
| 35 | + raise NameError("Key is not defined") |
| 36 | + # If the bruteforce flag used |
| 37 | + elif args.bruteforce: |
| 38 | + bruteforce_handler(args) |
| 39 | + # If the encrypt flag used |
| 40 | + elif args.encrypt: |
| 41 | + encrypt_handler(args) |
| 42 | + # If decrypt flag used, |
| 43 | + elif args.decrypt: |
| 44 | + decrypt_handler(args) |
| 45 | + # If no flags used, |
44 | 46 | else:
|
45 |
| - cracked = bruteforce(c_value) |
46 |
| - # Write to the file, |
47 |
| - # If an output path specified |
48 |
| - if args.output: |
49 |
| - write_file(cracked, args.output) |
50 |
| - else: |
51 |
| - for j in cracked: |
52 |
| - print(j) |
53 |
| - # If the encrypt flag used |
54 |
| - elif args.encrypt: |
55 |
| - # Extract key as an int from args |
56 |
| - key = int(''.join(map(str, args.key))) |
57 |
| - key *= -1 if args.backwards else 1 |
58 |
| - # Get plain text |
59 |
| - e_value = ' '.join(args.encrypt) |
60 |
| - # If source presents, |
61 |
| - # file content will be encrypted |
62 |
| - cipher = '' |
63 |
| - if args.sourceFile: |
64 |
| - f = open(e_value, 'r').read() |
65 |
| - cipher = encrypt(f, key) |
66 |
| - else: |
67 |
| - cipher = encrypt(e_value, key) |
68 |
| - # Write to the file, |
69 |
| - # If an output path specified |
70 |
| - if args.output: |
71 |
| - write_file(cipher, args.output) |
72 |
| - else: |
73 |
| - print("Encrypted: " + cipher) |
74 |
| - # If decrypt flag used, |
75 |
| - elif args.decrypt: |
76 |
| - # Extract key as an int from args |
77 |
| - key = int(''.join(map(str, args.key))) |
78 |
| - key *= -1 if args.backwards else 1 |
79 |
| - # Get Cipher text |
80 |
| - d_value = ' '.join(args.decrypt) |
81 |
| - # If source presents, |
82 |
| - # file content will be decrypted |
83 |
| - plain = '' |
84 |
| - if args.sourceFile: |
85 |
| - f = open(d_value, 'r').read() |
86 |
| - plain = decrypt(f, key) |
87 |
| - else: |
88 |
| - plain = decrypt(d_value, key) |
89 |
| - # Write to the file, |
90 |
| - # If an output path specified |
91 |
| - if args.output: |
92 |
| - write_file(plain, args.output) |
93 |
| - else: |
94 |
| - print("Decrypted: " + plain) |
95 |
| - # If no flags used, |
96 |
| - else: |
97 |
| - raise ValueError("No Arguments given") |
| 47 | + raise ValueError("No Arguments given") |
| 48 | + except Exception as e: |
| 49 | + print("Error:", e) |
0 commit comments