Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package bruteforce;
- import java.security.NoSuchAlgorithmException;
- import java.io.UnsupportedEncodingException;
- /**
- *
- * @author ejtay
- */
- public class bruteforce {
- private String[] charset;
- private String hashedPassword;
- private SHA1 hash;
- private String password;
- private boolean done = false;
- public bruteforce(String hash) throws NoSuchAlgorithmException, UnsupportedEncodingException {
- 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"};
- this.hash = new SHA1();
- this.hashedPassword = hash;
- generatePasswords("", 6);
- if(done){
- System.out.print("Password is:" + password + "\n");
- }
- }
- public void generatePasswords(String currentChar, int maxLen) throws NoSuchAlgorithmException, UnsupportedEncodingException{// generate passwords from charset a-z
- String hashed = hash.SHA1(currentChar);
- // System.out.print(hashed + "\n");
- if (hashed.equals(hashedPassword)){
- password = currentChar;
- this.done = true;
- }
- else{
- if (maxLen == 0){
- return;
- }
- for(int i = 0; i <= charset.length - 1; i++){
- String next = charset[i] + currentChar;
- if (!this.done){
- generatePasswords(next, maxLen - 1);
- }
- else{
- return;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement