Can anyone solve this code ?

Case Study: Script to Calculate Possible Password Combinations (keyspace) - Need help figuring this out The script should run but not do much yet! Now add your own code to your script, to calculate the ascii character combinations a brute force attack would need to try to exhaust the keyspace (using your code from above). The calculation is similar to the combinations of bits, but instead of a character set of two bits (0,1), ASCII has 95 (printable characters). Below is the code: def get_keyspace(passwd): """print the entropy value for an ascii password""" print('[*] keyspace') char_set = 4 keyspace = 4 # ... REPLACE WITH YOUR CODE HERE ... print(f'[*] Password: {passwd} - Total {keyspace} key combinations') # test case passwd = 'testings' # change the passwd variable to test # call keyspace calc function get_keyspace(passwd)

20th Sep 2020, 8:19 PM
kevin coyle
kevin coyle - avatar
1 Answer
+ 2
The following code should help solve your problem. I just don't fully understand the code you shared and ASCII contains 128 characters instead of 95. The get_keyspace function looks like it should print all the password combinations but then I don't know why a single password is passed as parameter to it instead of just a length. The following code defines a generator that iterates over all combinations of a given alphabet for the requested length. You can change the alphabet to whichever 95 characters you care about. alphabet = ' -_.,!@#$%^&*()[]{}<>;:+?|0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' def get_bruteforce_combinations_of_length(length): if length == 0: yield '' else: for i in range(len(alphabet)): prefix = alphabet[i] for suffix in get_bruteforce_combinations_of_length(length - 1): yield prefix + suffix # print all possible 2 character passwords. for password_guess in get_bruteforce_combinations_of_length(2): print(password_guess)
20th Sep 2020, 10:57 PM
Josh Greig
Josh Greig - avatar