File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1
1
from .crypt import encrypt , decrypt
2
2
from .utils import write_file
3
+ from .crack import bruteforce
3
4
import argparse
4
5
5
6
parser = argparse .ArgumentParser (
22
23
# -s & --source
23
24
parser .add_argument ('-sf' , '--sourceFile' , action = 'store_true' )
24
25
26
+ # -b & --brute
27
+ parser .add_argument ('-br' , '--bruteforce' , nargs = '+' ,
28
+ metavar = 'PLAIN' , help = 'Cipher text to crack' , type = str )
29
+
25
30
args = parser .parse_args ()
26
31
27
32
28
33
def handle_args ():
29
34
# If key isn't in the args,
30
35
if not args .key and (args .encrypt or args .decrypt ):
31
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 )
44
+ 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 )
32
53
# If the encrypt flag used
33
54
elif args .encrypt :
34
55
# Extract key as an int from args
Original file line number Diff line number Diff line change
1
+ from .crypt import ALPHEBET , decrypt
2
+
3
+ def bruteforce (text ):
4
+ cracked = []
5
+ for i in range (1 , len (ALPHEBET )):
6
+ cracked .append ('Result with key ' + str (i ) + ' ' + decrypt (text , i ))
7
+ return cracked
Original file line number Diff line number Diff line change 1
1
from pathlib import Path
2
2
3
+
3
4
def write_file (text , path ):
4
5
f = Path ('' .join (map (str , path )))
5
6
if f .exists ():
6
7
raise OSError ("File exists" )
7
8
with f .open ("w" , encoding = "utf-8" ) as f :
9
+ if type (text ) == list :
10
+ for item in text :
11
+ f .write ("%s\n " % item )
12
+ return
8
13
f .write (text )
You can’t perform that action at this time.
0 commit comments