feat: Guess password using hash table
This commit is contained in:
parent
a42d90871e
commit
335ed0d893
26
guesser.java
26
guesser.java
@ -1,3 +1,4 @@
|
|||||||
|
import java.io.*;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -19,17 +20,24 @@ public class guesser {
|
|||||||
|
|
||||||
boolean match = false;
|
boolean match = false;
|
||||||
int check=0;
|
int check=0;
|
||||||
while (!match) {
|
// Check hash table
|
||||||
String guess = getRandomPassword(check);
|
try{
|
||||||
check++;
|
BufferedReader reader = new BufferedReader(new FileReader("hashtable.txt"));
|
||||||
String hashedGuess = hash.hashstring(guess);
|
String line;
|
||||||
if (hashedGuess.equals(hashed)) {
|
int lineNumber = 0;
|
||||||
match = true;
|
|
||||||
System.out.println("Match!");
|
while ((line = reader.readLine()) != null) {
|
||||||
System.out.println("Password is: " + guess);
|
lineNumber++;
|
||||||
|
if (line.contains(hashed)) {
|
||||||
|
System.out.println("Match!");
|
||||||
|
System.out.println("Password is: " + line.split("\\$")[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long endTime = System.nanoTime();
|
long endTime = System.nanoTime();
|
||||||
long duration = (endTime - startTime);
|
long duration = (endTime - startTime);
|
||||||
// Calculate the time taken in seconds
|
// Calculate the time taken in seconds
|
||||||
@ -99,7 +107,7 @@ public class guesser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getRandomPassword(int value) {
|
public static String getRandomPassword(int value) {
|
||||||
// Define the characters that can be used in the random string
|
// Define the characters that can be used in the random string
|
||||||
String characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
String characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
|
||||||
|
33
hashTable.java
Normal file
33
hashTable.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import java.io.File;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
public class hashTable {
|
||||||
|
public static void main(String[] args) throws NoSuchAlgorithmException {
|
||||||
|
System.out.println("Hashing all 6 digit passwords");
|
||||||
|
// Save to hashtable.txt
|
||||||
|
File file = new File("hashtable.txt");
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
// Create a new file in the current directory
|
||||||
|
try {
|
||||||
|
file.createNewFile();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write to the file
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < 1000000; i++) {
|
||||||
|
String randomPassword = guesser.getRandomPassword(i);
|
||||||
|
String hashed = hash.hashstring(randomPassword);
|
||||||
|
String line = randomPassword + "$" + hashed + "\n";
|
||||||
|
try {
|
||||||
|
java.nio.file.Files.write(java.nio.file.Paths.get("hashtable.txt"), line.getBytes(), java.nio.file.StandardOpenOption.APPEND);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1000000
hashtable.txt
Normal file
1000000
hashtable.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user