Browse Source

Initial commit

master
Robby Zambito 1 year ago
commit
b31aff837e
6 changed files with 9864 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +32
    -0
      BruteGenerator.java
  3. +46
    -0
      Main.java
  4. +65
    -0
      PasswordTable.java
  5. +9716
    -0
      Passwords.txt
  6. +3
    -0
      README.md

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
Passwords - Copy.txt
*.class

+ 32
- 0
BruteGenerator.java View File

@@ -0,0 +1,32 @@
public class BruteGenerator {
private static char[] charArr = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
};
private int seed;
private int length;
public BruteGenerator() {
seed = 0;
length = 1;
}
public String next() {
String result = "";
if(seed + 1 > Math.pow(charArr.length, length)) {
length++;
seed = 0;
}
for(int i = 0; i < length; i++) {
result += Character.toString(charArr[(int) (seed / Math.pow(charArr.length, i)) % charArr.length]);
}
seed++;
return result;
}
}

+ 46
- 0
Main.java View File

@@ -0,0 +1,46 @@
import java.io.IOException;
import java.io.File;
import java.util.Scanner;
import java.io.PrintStream;
import java.util.Iterator;

public class Main {
public static void main(String[] args) throws IOException {
File file = new File("Passwords.txt");
Scanner fileScanner = new Scanner(file);
Scanner scan = new Scanner(System.in);
PrintStream fileOut;
PasswordTable passwordTable = new PasswordTable();
BruteGenerator bruteGenerator = new BruteGenerator();
String secretPassword;
while(fileScanner.hasNextLine()) {
String curLine = fileScanner.nextLine();
passwordTable.put(curLine.split(":")[0], Integer.parseInt(curLine.split(":")[1]));
}
System.out.print("Enter a \"secret\" password: ");
secretPassword = scan.nextLine();
String guess = "";
int tries = 0;
do {
tries++;
if(Math.log(tries) / Math.log(2) % 1 == 0)
guess = passwordTable.next();
else
guess = bruteGenerator.next();
}while(!guess.equals(secretPassword));
System.out.println("Your password was: " + guess + "\nFound in " + tries + " tries.");
passwordTable.put(guess);
fileOut = new PrintStream(file);
for(Iterator i = passwordTable.iterator(); i.hasNext();)
fileOut.println(i.next());
}
}

+ 65
- 0
PasswordTable.java View File

@@ -0,0 +1,65 @@
import java.util.ArrayList;
import java.lang.Iterable;
import java.util.Iterator;

public class PasswordTable implements Iterable {
private static class Entry {
private String password;
private Integer score;
Entry(String password, Integer score) {
this.password = password;
this.score = score;
}
public String toString() {
return password + ":" + score;
}
}
private ArrayList<Entry> entries;
private int next = 0;
public PasswordTable() {
entries = new ArrayList<Entry>();
}
public void put(String password, int score) {
entries.add(new Entry(password, score));
}
public void put(String password) {
boolean containsEntry = false;
int index = -1;
for(Entry e : entries) {
index++;
if(e.password.equals(password)) {
containsEntry = true;
break;
}
}
if(containsEntry) {
entries.set(index, new Entry(password, entries.get(index).score + 1));
while(index > 0 && entries.get(index).score > entries.get(index - 1).score) {
Entry oldUpperEntry = entries.get(index - 1);
entries.set(index - 1, entries.get(index));
entries.set(index, oldUpperEntry);
index--;
}
}
else
entries.add(new Entry(password, 1));
}
public String next() {
return next < entries.size() ? entries.get(next++).password : "";
}
public Iterator<Entry> iterator() {
return entries.iterator();
}
}

+ 9716
- 0
Passwords.txt
File diff suppressed because it is too large
View File


+ 3
- 0
README.md View File

@@ -0,0 +1,3 @@
# AIPasswordCracker

This project was initially created by me in December 2016. I created this project to use persistent state to try optimizing a brute force "password cracker". The project works by accepting an input string to try to match against, and applying a simple brute force to match against it. Previous successful matches are then stored in Passwords.txt, given a "score" of the number of matches against that password, and then ranked by score. When brute forcing future passwords, previous successful matches are then attempted along with the normal brute force, so that more commonly successful matches are attempted more commonly. There are a number of things I did that aren't considered good practice, but I', leaving this as is to benchmark my progress as a programmer.