Facebook
From Ivory Hog, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 75
  1. //        Brute force password cracker 1.0
  2. //        Copyright (C) 2020  Henrik Riskær
  3.  
  4. //        This program was written for the Essential Programming course at Roskilde
  5. //        University as part of the curricular coding assignments.
  6.  
  7. //        This program is free software; you can redistribute it and/or
  8. //        modify it under the terms of the GNU General Public License
  9. //        as published by the Free Software Foundation; either version 2
  10. //        of the License, or (at your option) any later version.
  11.  
  12. //        This program is distributed in the hope that it will be useful,
  13. //        but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. //        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. //        GNU General Public License for more details.
  16.  
  17. //        You should have received a copy of the GNU General Public License
  18. //        along with this program; if not, write to the Free Software
  19. //        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  20.  
  21.  
  22. import java.util.Arrays;
  23. import java.util.Random;
  24.  
  25. public class Main {
  26.  
  27.  
  28.     public static void main(String[] args){
  29.         int[] pw = pwGen(4);
  30.         System.out.println("Starting bruteforce of array...");
  31.         printArray(pw);
  32.         int solution = attack(pw);
  33.         System.out.println("Password Successfully brute forced. password is: " + solution);
  34.     }
  35.  
  36.     public static int[] pwGen(int digits){
  37.         Random rand = new Random(123);
  38.         int[] pw = new int[digits];
  39.         for(int i = 0; i < digits; i++){
  40.             pw[i] = rand.nextInt(10);
  41.         }
  42.         return pw;
  43.  
  44.     }
  45.     public static void printArray(int[] diller){
  46.         System.out.print("[");
  47.         for(int i = 0; i < diller.length; i++){
  48.             System.out.print(diller[i]);
  49.             System.out.print(", ");
  50.         }
  51.         System.out.print("]");
  52.     }
  53.  
  54.     public static int arrayToInt(int[] intKassen){
  55.         int res = 0;
  56.         for (int i=0; i < intKassen.length; i++){
  57.            res = res*10;
  58.            res = res+intKassen[i];
  59.  
  60.         }
  61.         return res;
  62.     }
  63.     public static int attack(int[] pw){
  64.         int n = arrayToInt(pw);
  65.         int i = 0;
  66.         for (i = 0; i < n; i++){
  67.             if(i != n){
  68.                 System.out.println("it wasn't " + i);
  69.             }
  70.  
  71.         }
  72.         return i;
  73.  
  74.     }
  75. }