Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hacking;
- import java.util.Arrays;
- import java.util.Scanner;
- public class BruteForce {
- @SuppressWarnings("resource")
- public static void main(String[] args)
- {
- //Information
- System.out.println("*******************\n|PLEASE ONLY USE | \n|EXACTLY WHAT YOU | \n|ARE TOLD TO TYPE,|");
- System.out.println("|THE PROGRAM WILL | \n|NOT ACCEPT ANYT- |\n|HING ELSE | \n*******************");
- //Start, (Y/N)
- System.out.println("Begin Program? \nYes -> true \nNo -> false");
- Scanner sc = new Scanner(System.in);
- boolean Start = sc.nextBoolean();
- System.out.println("*******************");
- System.out.println("Are You Sure? \nYes -> true \nNo -> false");
- Start = sc.nextBoolean();
- System.out.println("*******************");
- //Work start prompt
- if (Start == true) {
- System.out.println("Begining Program\n*******************\n| Lower case only |\n*******************");
- }
- else {
- System.out.println("Terminating program");
- System.exit(1);
- }
- //Set Password
- System.out.println("Password to hack:");
- Scanner sx = new Scanner(System.in);
- String password = sx.nextLine();
- System.out.println("*******************");
- System.out.println("-Begining Hacking-");
- System.out.println("*******************");
- /*
- Set guess Pool
- Pool: Alphabet, SPACE
- */
- long startTime = System.nanoTime();
- char[] charset = "abcdefghijklmnopqrstuvwxyz ".toCharArray();
- BruteForce bf = new BruteForce(charset, 1);
- String attempt = bf.toString();
- //Test if guess is correct
- while (true) {
- //If correct
- if (attempt.equals(password)) {
- System.out.println("Password Found: \n" + attempt);
- break; }
- //If wrong
- attempt = bf.toString();
- System.out.println("Tried: '" + attempt + "'");
- bf.increment();
- }
- //Timer
- long estimatedTime = System.nanoTime() - startTime;
- System.out.println("Time taken: \n" + estimatedTime + " ns");
- }
- private char[] cs;
- // Character Set
- private char[] cg;
- // Current Guess
- public BruteForce(char[] characterSet, int guessLength)
- { cs = characterSet;
- cg = new char[guessLength];
- Arrays.fill(cg, cs[0]); }
- //Password Generation
- public void increment() {
- int index = cg.length - 1;
- while(index >= 0) {
- if (cg[index] == cs[cs.length-1]) {
- if (index == 0) {
- cg = new char[cg.length+1];
- Arrays.fill(cg, cs[0]);
- break; }
- else {
- cg[index] = cs[0];
- index--; }
- }
- else {
- cg[index] = cs[Arrays.binarySearch(cs, cg[index]) + 1];
- break;
- }
- }
- }
- public String toString() {
- //Send generated password off to checking method
- return String.valueOf(cg); }
- }
Add Comment
Please, Sign In to add comment