THINK FIRST·CODE LATER

← All labs

Password search spaces and hashing speed

Problem

Input: the number of hash functions h, then h lines name guessesPerSecond; then password policies label alphabetSize length until the end of input.

For each policy compute the search space alphabet^length, the entropy length × log₂(alphabet) bits, and for each hash the average cracking time = space / 2 / rate. Print:

mixed8: 62^8 = 2.18e+14 guesses, 47.6 bits; average time: MD5 3.0 hours, bcrypt12 345.9 years

Time format: < 1 second below 1 s; otherwise the largest unit among seconds, minutes, hours, days, years (365.25 days) with 1 decimal; for ≥ 10⁶ years use the form 7.5e+11 years.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os14-3-data-1.txt

2
MD5 1e10
bcrypt12 1e4
PIN4 10 4
lower8 26 8
mixed8 62 8
full12 94 12
passphrase4 7776 4
What your program must print for os14-3-data-1.txt
PIN4: 10^4 = 1.00e+04 guesses, 13.3 bits; average time: MD5 < 1 second, bcrypt12 < 1 second
lower8: 26^8 = 2.09e+11 guesses, 37.6 bits; average time: MD5 10.4 seconds, bcrypt12 120.8 days
mixed8: 62^8 = 2.18e+14 guesses, 47.6 bits; average time: MD5 3.0 hours, bcrypt12 345.9 years
full12: 94^12 = 4.76e+23 guesses, 78.7 bits; average time: MD5 754050.2 years, bcrypt12 7.5e+11 years
passphrase4: 7776^4 = 3.66e+15 guesses, 51.7 bits; average time: MD5 2.1 days, bcrypt12 5792.8 years

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os14-3-data-1.txt

Windows PowerShell does not understand <:

Get-Content os14-3-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.