TBSpeed

Chemistry hacking program

Apr 28th, 2015
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.81 KB | None | 0 0
  1. package hacking;
  2.         import java.util.Arrays;
  3.         import java.util.Scanner;
  4.         public class BruteForce {
  5.                 @SuppressWarnings("resource")
  6.                 public static void main(String[] args)
  7.                 {
  8.                 //Information
  9.                 System.out.println("*******************\n|PLEASE ONLY USE  | \n|EXACTLY WHAT YOU | \n|ARE TOLD TO TYPE,|");
  10.                 System.out.println("|THE PROGRAM WILL | \n|NOT ACCEPT ANYT- |\n|HING ELSE        | \n*******************");
  11.                 //Start, (Y/N)
  12.                 System.out.println("Begin Program? \nYes -> true \nNo  -> false");
  13.                 Scanner sc = new Scanner(System.in);
  14.             boolean Start = sc.nextBoolean();
  15.             System.out.println("*******************");
  16.             System.out.println("Are You Sure? \nYes -> true \nNo  -> false");
  17.             Start = sc.nextBoolean();
  18.             System.out.println("*******************");
  19.             //Work start prompt
  20.             if (Start == true) {
  21.                 System.out.println("Begining Program\n*******************\n| Lower case only |\n*******************");
  22.             }
  23.             else {
  24.                 System.out.println("Terminating program");
  25.                 System.exit(1);
  26.             }
  27.             //Set Password
  28.             System.out.println("Password to hack:");
  29.                 Scanner sx = new Scanner(System.in);
  30.                 String password = sx.nextLine();
  31.                 System.out.println("*******************");
  32.                 System.out.println("-Begining  Hacking-");
  33.                 System.out.println("*******************");
  34.             /*
  35.              Set guess Pool
  36.              Pool: Alphabet, SPACE
  37.              */
  38.             long startTime = System.nanoTime();
  39.                 char[] charset = "abcdefghijklmnopqrstuvwxyz ".toCharArray();
  40.                 BruteForce bf = new BruteForce(charset, 1);      
  41.                 String attempt = bf.toString();      
  42.             //Test if guess is correct
  43.                 while (true) {        
  44.             //If correct
  45.                         if (attempt.equals(password)) {
  46.                                 System.out.println("Password Found: \n" + attempt);
  47.                                 break;          }
  48.             //If wrong
  49.                         attempt = bf.toString();
  50.                         System.out.println("Tried: '" + attempt + "'");
  51.                         bf.increment();
  52.                         }
  53.             //Timer
  54.                 long estimatedTime = System.nanoTime() - startTime;
  55.                 System.out.println("Time taken: \n" + estimatedTime + " ns");
  56.             }
  57.                 private char[] cs;
  58.             // Character Set
  59.                 private char[] cg;
  60.             // Current Guess
  61.                 public BruteForce(char[] characterSet, int guessLength)
  62.                 {       cs = characterSet;      
  63.                 cg = new char[guessLength];      
  64.                 Arrays.fill(cg, cs[0]);    }    
  65.             //Password Generation
  66.                 public void increment() {      
  67.                         int index = cg.length - 1;      
  68.                         while(index >= 0) {          
  69.                                 if (cg[index] == cs[cs.length-1]) {            
  70.                                         if (index == 0) {                
  71.                                                 cg = new char[cg.length+1];                
  72.                                                 Arrays.fill(cg, cs[0]);                
  73.                                                 break;             }
  74.                                         else {                
  75.                                                 cg[index] = cs[0];                
  76.                                                 index--;             }
  77.                                         }
  78.                                 else {            
  79.                                         cg[index] = cs[Arrays.binarySearch(cs, cg[index]) + 1];
  80.                                         break;
  81.                                         }
  82.                                 }
  83.                         }    
  84.                 public String toString() {
  85.             //Send generated password off to checking method
  86.                         return String.valueOf(cg);    }
  87.                
  88.  
  89.     }
Add Comment
Please, Sign In to add comment