Advertisement
Guest User

bruteforce.java - Erlo Tayamen

a guest
Nov 23rd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package bruteforce;
  7.  
  8. import java.security.NoSuchAlgorithmException;
  9. import java.io.UnsupportedEncodingException;
  10. /**
  11.  *
  12.  * @author ejtay
  13.  */
  14. public class bruteforce {
  15.    
  16.     private String[] charset;
  17.     private String hashedPassword;
  18.     private SHA1 hash;
  19.     private String password;
  20.     private boolean done = false;
  21.  
  22.     public bruteforce(String hash) throws NoSuchAlgorithmException, UnsupportedEncodingException {
  23.         this.charset = new String[]{"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"};
  24.         this.hash = new SHA1();
  25.         this.hashedPassword = hash;
  26.         generatePasswords("", 6);
  27.         if(done){
  28.             System.out.print("Password is:" + password + "\n");
  29.         }
  30.     }
  31.    
  32.     public void generatePasswords(String currentChar, int maxLen) throws NoSuchAlgorithmException, UnsupportedEncodingException{// generate passwords from charset a-z
  33.         String hashed = hash.SHA1(currentChar);
  34.        // System.out.print(hashed + "\n");
  35.         if (hashed.equals(hashedPassword)){
  36.             password = currentChar;
  37.             this.done = true;
  38.         }
  39.         else{
  40.             if (maxLen == 0){
  41.                 return;
  42.             }
  43.             for(int i = 0; i <= charset.length - 1; i++){
  44.                 String next = charset[i] + currentChar;
  45.                 if (!this.done){
  46.                     generatePasswords(next, maxLen - 1);
  47.                 }
  48.                 else{
  49.                     return;
  50.                 }
  51.             }
  52.         }
  53.        
  54.     }
  55.    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement