Advertisement
dawciobiel

password brute-force generator

Mar 17th, 2020
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 8.37 KB | None | 0 0
  1. import model.CharacterTable;
  2.  
  3. import java.util.Iterator;
  4. import java.util.Vector;
  5.  
  6. public class RecursiveGenerator {
  7.  
  8.     private static int I_PASSWORD_LENGTH = 3;
  9.     private static char[] CHARS = new char[CharacterTable.getAllCharacters().size()];
  10.  
  11.     public static void main(String[] args) {
  12.         RecursiveGenerator recursiveGenerator = new RecursiveGenerator();
  13.         recursiveGenerator.generate();
  14.     }
  15.  
  16.     public Vector<String> generate() {
  17.         Iterator<char[]> iterator = CharacterTable.getAllCharacters().iterator();
  18.  
  19.         int idx = 0;
  20.         while (iterator.hasNext()) {
  21.             CHARS[idx] = iterator.next()[0];
  22.             idx++;
  23.         }
  24.  
  25.         GenerateAllPasswords("", 0, I_PASSWORD_LENGTH);
  26.  
  27.         return generatedString;
  28.     }
  29.  
  30.     private void GenerateAllPasswords(String password, int pos, int siz) {
  31.         if (pos < siz) {
  32.             for (char ch : CHARS) {
  33.                 GenerateAllPasswords(pwd + ch, pos + 1, siz);
  34.             }
  35.         } else {
  36.             System.out.println(password);
  37.             /* Instead, execute the archiver with the appropriate switches from the command line
  38.              * e.g.: 7z t archive.zip * -r -p {password}  
  39.              */
  40.         }
  41.     }
  42. }
  43.  
  44. package model;
  45.  
  46. import lombok.NoArgsConstructor;
  47.  
  48. import java.util.ArrayList;
  49. import java.util.Collections;
  50. import java.util.List;
  51.  
  52. // TODO Refactor this class-it should be as singleton.
  53. public class CharacterTable {
  54.     public static List<char[]> allCharacters;
  55.     /**
  56.      * ASCII Punctuation & Symbols #1
  57.      * U+0020   32  Space   0001
  58.      * U+0021   !   33  Exclamation mark    0002
  59.      * U+0022   "   34  Quotation mark  0003
  60.      * U+0023   #   35  Number sign, Hashtag, Octothorpe, Sharp     0004
  61.      * U+0024   $   36  Dollar sign     0005
  62.      * U+0025   %   37  Percent sign    0006
  63.      * U+0026   &   38  Ampersand   0007
  64.      * U+0027   '   39  Apostrophe  0008
  65.      * U+0028   (   40  Left parenthesis    0009
  66.      * U+0029   )   41  Right parenthesis   0010
  67.      * U+002A   *   42  Asterisk    0011
  68.      * U+002B   +   43  Plus sign   0012
  69.      * U+002C   ,   44  Comma   0013
  70.      * U+002D   -   45  Hyphen-minus    0014
  71.      * U+002E   .   46  Full stop   0015
  72.      * U+002F   /   47  Slash (Solidus)     0016
  73.      */
  74.     private static List<char[]> punctuation_and_symbols_1;
  75.     /**
  76.      * ASCII Digits
  77.      * U+0030   0   48  Digit Zero  0017
  78.      * U+0031   1   49  Digit One   0018
  79.      * U+0032   2   50  Digit Two   0019
  80.      * U+0033   3   51  Digit Three     0020
  81.      * U+0034   4   52  Digit Four  0021
  82.      * U+0035   5   53  Digit Five  0022
  83.      * U+0036   6   54  Digit Six   0023
  84.      * U+0037   7   55  Digit Seven     0024
  85.      * U+0038   8   56  Digit Eight     0025
  86.      * U+0039   9   57  Digit Nine  0026
  87.      */
  88.     private static List<char[]> digits;
  89.     /**
  90.      * ASCII Punctuation & Symbols #2
  91.      * U+003A   :   58  Colon   0027
  92.      * U+003B   ;   59  Semicolon   0028
  93.      * U+003C   <   60  Less-than sign  0029
  94.      * U+003D   =   61  Equal sign  0030
  95.      * U+003E   >   62  Greater-than sign   0031
  96.      * U+003F   ?   63  Question mark   0032
  97.      * U+0040   @   64  At sign     0033
  98.      */
  99.     private static List<char[]> punctuation_and_symbols_2;
  100.     /**
  101.      * Latin Alphabet Uppercase
  102.      * U+0041   A   65  Latin Capital letter A  0034
  103.      * U+0042   B   66  Latin Capital letter B  0035
  104.      * U+0043   C   67  Latin Capital letter C  0036
  105.      * U+0044   D   68  Latin Capital letter D  0037
  106.      * U+0045   E   69  Latin Capital letter E  0038
  107.      * U+0046   F   70  Latin Capital letter F  0039
  108.      * U+0047   G   71  Latin Capital letter G  0040
  109.      * U+0048   H   72  Latin Capital letter H  0041
  110.      * U+0049   I   73  Latin Capital letter I  0042
  111.      * U+004A   J   74  Latin Capital letter J  0043
  112.      * U+004B   K   75  Latin Capital letter K  0044
  113.      * U+004C   L   76  Latin Capital letter L  0045
  114.      * U+004D   M   77  Latin Capital letter M  0046
  115.      * U+004E   N   78  Latin Capital letter N  0047
  116.      * U+004F   O   79  Latin Capital letter O  0048
  117.      * U+0050   P   80  Latin Capital letter P  0049
  118.      * U+0051   Q   81  Latin Capital letter Q  0050
  119.      * U+0052   R   82  Latin Capital letter R  0051
  120.      * U+0053   S   83  Latin Capital letter S  0052
  121.      * U+0054   T   84  Latin Capital letter T  0053
  122.      * U+0055   U   85  Latin Capital letter U  0054
  123.      * U+0056   V   86  Latin Capital letter V  0055
  124.      * U+0057   W   87  Latin Capital letter W  0056
  125.      * U+0058   X   88  Latin Capital letter X  0057
  126.      * U+0059   Y   89  Latin Capital letter Y  0058
  127.      * U+005A   Z   90  Latin Capital letter Z  0059
  128.      */
  129.     private static List<char[]> latin_alphabet_uppercase;
  130.     /**
  131.      * ASCII Punctuation & Symbols #3
  132.      * U+005B   [   91  Left Square Bracket     0060
  133.      * U+005C   \   92  Backslash   0061
  134.      * U+005D   ]   93  Right Square Bracket    0062
  135.      * U+005E   ^   94  Circumflex accent   0063
  136.      * U+005F   _   95  Low line    0064
  137.      * U+0060   `   96  Grave accent    0065
  138.      */
  139.     private static List<char[]> punctuation_and_symbols_3;
  140.     /**
  141.      * Latin Alphabet Lowercase
  142.      * U+0061   a   97  Latin Small Letter A    0066
  143.      * U+0062   b   98  Latin Small Letter B    0067
  144.      * U+0063   c   99  Latin Small Letter C    0068
  145.      * U+0064   d   100     Latin Small Letter D    0069
  146.      * U+0065   e   101     Latin Small Letter E    0070
  147.      * U+0066   f   102     Latin Small Letter F    0071
  148.      * U+0067   g   103     Latin Small Letter G    0072
  149.      * U+0068   h   104     Latin Small Letter H    0073
  150.      * U+0069   i   105     Latin Small Letter I    0074
  151.      * U+006A   j   106     Latin Small Letter J    0075
  152.      * U+006B   k   107     Latin Small Letter K    0076
  153.      * U+006C   l   108     Latin Small Letter L    0077
  154.      * U+006D   m   109     Latin Small Letter M    0078
  155.      * U+006E   n   110     Latin Small Letter N    0079
  156.      * U+006F   o   111     Latin Small Letter O    0080
  157.      * U+0070   p   112     Latin Small Letter P    0081
  158.      * U+0071   q   113     Latin Small Letter Q    0082
  159.      * U+0072   r   114     Latin Small Letter R    0083
  160.      * U+0073   s   115     Latin Small Letter S    0084
  161.      * U+0074   t   116     Latin Small Letter T    0085
  162.      * U+0075   u   117     Latin Small Letter U    0086
  163.      * U+0076   v   118     Latin Small Letter V    0087
  164.      * U+0077   w   119     Latin Small Letter W    0088
  165.      * U+0078   x   120     Latin Small Letter X    0089
  166.      * U+0079   y   121     Latin Small Letter Y    0090
  167.      * U+007A   z   122     Latin Small Letter Z    0091
  168.      */
  169.     private static List<char[]> latin_alphabet_lowercase;
  170.     /**
  171.      * ASCII Punctuation & Symbols #4
  172.      * U+007B   {   123     Left Curly Bracket  0092
  173.      * U+007C   |   124     Vertical bar    0093
  174.      * U+007D   }   125     Right Curly Bracket     0094
  175.      * U+007E   ~   126     Tilde   0095
  176.      */
  177.     private static List<char[]> punctuation_and_symbols_4;
  178.  
  179.     {
  180.         punctuation_and_symbols_1 = generateCharactersList(32, 47);
  181.         digits = generateCharactersList(48, 57);
  182.         punctuation_and_symbols_2 = generateCharactersList(58, 64);
  183.         latin_alphabet_uppercase = generateCharactersList(65, 90);
  184.         punctuation_and_symbols_3 = generateCharactersList(91, 96);
  185.         latin_alphabet_lowercase = generateCharactersList(97, 122);
  186.         punctuation_and_symbols_4 = generateCharactersList(123, 126);
  187.  
  188.         allCharacters = new ArrayList<>(
  189.                 punctuation_and_symbols_1.size() +
  190.                         digits.size() +
  191.                         punctuation_and_symbols_2.size() +
  192.                         latin_alphabet_uppercase.size() +
  193.                         punctuation_and_symbols_3.size() +
  194.                         latin_alphabet_lowercase.size() +
  195.                         punctuation_and_symbols_4.size()
  196.         );
  197.  
  198.         allCharacters.addAll(punctuation_and_symbols_1);
  199.         allCharacters.addAll(digits);
  200.         allCharacters.addAll(punctuation_and_symbols_2);
  201.         allCharacters.addAll(latin_alphabet_uppercase);
  202.         allCharacters.addAll(punctuation_and_symbols_3);
  203.         allCharacters.addAll(latin_alphabet_lowercase);
  204.         allCharacters.addAll(punctuation_and_symbols_4);
  205.     }
  206.  
  207.     public static List<char[]> getAllCharacters() {
  208.         new CharacterTable();
  209.         return allCharacters;
  210.     }
  211.  
  212.     private static List<char[]> generateCharactersList(int firstCharacterCode, int lastCharacterCode) {
  213.         List<char[]> list = new ArrayList<>(lastCharacterCode - firstCharacterCode);
  214.         for (int i = firstCharacterCode; i <= (lastCharacterCode); i++) {
  215.             list.add(Character.toChars(i));
  216.         }
  217.         return list;
  218.     }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement