Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import model.CharacterTable;
- import java.util.Iterator;
- import java.util.Vector;
- public class RecursiveGenerator {
- private static int I_PASSWORD_LENGTH = 3;
- private static char[] CHARS = new char[CharacterTable.getAllCharacters().size()];
- public static void main(String[] args) {
- RecursiveGenerator recursiveGenerator = new RecursiveGenerator();
- recursiveGenerator.generate();
- }
- public Vector<String> generate() {
- Iterator<char[]> iterator = CharacterTable.getAllCharacters().iterator();
- int idx = 0;
- while (iterator.hasNext()) {
- CHARS[idx] = iterator.next()[0];
- idx++;
- }
- GenerateAllPasswords("", 0, I_PASSWORD_LENGTH);
- return generatedString;
- }
- private void GenerateAllPasswords(String password, int pos, int siz) {
- if (pos < siz) {
- for (char ch : CHARS) {
- GenerateAllPasswords(pwd + ch, pos + 1, siz);
- }
- } else {
- System.out.println(password);
- /* Instead, execute the archiver with the appropriate switches from the command line
- * e.g.: 7z t archive.zip * -r -p {password}
- */
- }
- }
- }
- package model;
- import lombok.NoArgsConstructor;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- // TODO Refactor this class-it should be as singleton.
- public class CharacterTable {
- public static List<char[]> allCharacters;
- /**
- * ASCII Punctuation & Symbols #1
- * U+0020 32 Space 0001
- * U+0021 ! 33 Exclamation mark 0002
- * U+0022 " 34 Quotation mark 0003
- * U+0023 # 35 Number sign, Hashtag, Octothorpe, Sharp 0004
- * U+0024 $ 36 Dollar sign 0005
- * U+0025 % 37 Percent sign 0006
- * U+0026 & 38 Ampersand 0007
- * U+0027 ' 39 Apostrophe 0008
- * U+0028 ( 40 Left parenthesis 0009
- * U+0029 ) 41 Right parenthesis 0010
- * U+002A * 42 Asterisk 0011
- * U+002B + 43 Plus sign 0012
- * U+002C , 44 Comma 0013
- * U+002D - 45 Hyphen-minus 0014
- * U+002E . 46 Full stop 0015
- * U+002F / 47 Slash (Solidus) 0016
- */
- private static List<char[]> punctuation_and_symbols_1;
- /**
- * ASCII Digits
- * U+0030 0 48 Digit Zero 0017
- * U+0031 1 49 Digit One 0018
- * U+0032 2 50 Digit Two 0019
- * U+0033 3 51 Digit Three 0020
- * U+0034 4 52 Digit Four 0021
- * U+0035 5 53 Digit Five 0022
- * U+0036 6 54 Digit Six 0023
- * U+0037 7 55 Digit Seven 0024
- * U+0038 8 56 Digit Eight 0025
- * U+0039 9 57 Digit Nine 0026
- */
- private static List<char[]> digits;
- /**
- * ASCII Punctuation & Symbols #2
- * U+003A : 58 Colon 0027
- * U+003B ; 59 Semicolon 0028
- * U+003C < 60 Less-than sign 0029
- * U+003D = 61 Equal sign 0030
- * U+003E > 62 Greater-than sign 0031
- * U+003F ? 63 Question mark 0032
- * U+0040 @ 64 At sign 0033
- */
- private static List<char[]> punctuation_and_symbols_2;
- /**
- * Latin Alphabet Uppercase
- * U+0041 A 65 Latin Capital letter A 0034
- * U+0042 B 66 Latin Capital letter B 0035
- * U+0043 C 67 Latin Capital letter C 0036
- * U+0044 D 68 Latin Capital letter D 0037
- * U+0045 E 69 Latin Capital letter E 0038
- * U+0046 F 70 Latin Capital letter F 0039
- * U+0047 G 71 Latin Capital letter G 0040
- * U+0048 H 72 Latin Capital letter H 0041
- * U+0049 I 73 Latin Capital letter I 0042
- * U+004A J 74 Latin Capital letter J 0043
- * U+004B K 75 Latin Capital letter K 0044
- * U+004C L 76 Latin Capital letter L 0045
- * U+004D M 77 Latin Capital letter M 0046
- * U+004E N 78 Latin Capital letter N 0047
- * U+004F O 79 Latin Capital letter O 0048
- * U+0050 P 80 Latin Capital letter P 0049
- * U+0051 Q 81 Latin Capital letter Q 0050
- * U+0052 R 82 Latin Capital letter R 0051
- * U+0053 S 83 Latin Capital letter S 0052
- * U+0054 T 84 Latin Capital letter T 0053
- * U+0055 U 85 Latin Capital letter U 0054
- * U+0056 V 86 Latin Capital letter V 0055
- * U+0057 W 87 Latin Capital letter W 0056
- * U+0058 X 88 Latin Capital letter X 0057
- * U+0059 Y 89 Latin Capital letter Y 0058
- * U+005A Z 90 Latin Capital letter Z 0059
- */
- private static List<char[]> latin_alphabet_uppercase;
- /**
- * ASCII Punctuation & Symbols #3
- * U+005B [ 91 Left Square Bracket 0060
- * U+005C \ 92 Backslash 0061
- * U+005D ] 93 Right Square Bracket 0062
- * U+005E ^ 94 Circumflex accent 0063
- * U+005F _ 95 Low line 0064
- * U+0060 ` 96 Grave accent 0065
- */
- private static List<char[]> punctuation_and_symbols_3;
- /**
- * Latin Alphabet Lowercase
- * U+0061 a 97 Latin Small Letter A 0066
- * U+0062 b 98 Latin Small Letter B 0067
- * U+0063 c 99 Latin Small Letter C 0068
- * U+0064 d 100 Latin Small Letter D 0069
- * U+0065 e 101 Latin Small Letter E 0070
- * U+0066 f 102 Latin Small Letter F 0071
- * U+0067 g 103 Latin Small Letter G 0072
- * U+0068 h 104 Latin Small Letter H 0073
- * U+0069 i 105 Latin Small Letter I 0074
- * U+006A j 106 Latin Small Letter J 0075
- * U+006B k 107 Latin Small Letter K 0076
- * U+006C l 108 Latin Small Letter L 0077
- * U+006D m 109 Latin Small Letter M 0078
- * U+006E n 110 Latin Small Letter N 0079
- * U+006F o 111 Latin Small Letter O 0080
- * U+0070 p 112 Latin Small Letter P 0081
- * U+0071 q 113 Latin Small Letter Q 0082
- * U+0072 r 114 Latin Small Letter R 0083
- * U+0073 s 115 Latin Small Letter S 0084
- * U+0074 t 116 Latin Small Letter T 0085
- * U+0075 u 117 Latin Small Letter U 0086
- * U+0076 v 118 Latin Small Letter V 0087
- * U+0077 w 119 Latin Small Letter W 0088
- * U+0078 x 120 Latin Small Letter X 0089
- * U+0079 y 121 Latin Small Letter Y 0090
- * U+007A z 122 Latin Small Letter Z 0091
- */
- private static List<char[]> latin_alphabet_lowercase;
- /**
- * ASCII Punctuation & Symbols #4
- * U+007B { 123 Left Curly Bracket 0092
- * U+007C | 124 Vertical bar 0093
- * U+007D } 125 Right Curly Bracket 0094
- * U+007E ~ 126 Tilde 0095
- */
- private static List<char[]> punctuation_and_symbols_4;
- {
- punctuation_and_symbols_1 = generateCharactersList(32, 47);
- digits = generateCharactersList(48, 57);
- punctuation_and_symbols_2 = generateCharactersList(58, 64);
- latin_alphabet_uppercase = generateCharactersList(65, 90);
- punctuation_and_symbols_3 = generateCharactersList(91, 96);
- latin_alphabet_lowercase = generateCharactersList(97, 122);
- punctuation_and_symbols_4 = generateCharactersList(123, 126);
- allCharacters = new ArrayList<>(
- punctuation_and_symbols_1.size() +
- digits.size() +
- punctuation_and_symbols_2.size() +
- latin_alphabet_uppercase.size() +
- punctuation_and_symbols_3.size() +
- latin_alphabet_lowercase.size() +
- punctuation_and_symbols_4.size()
- );
- allCharacters.addAll(punctuation_and_symbols_1);
- allCharacters.addAll(digits);
- allCharacters.addAll(punctuation_and_symbols_2);
- allCharacters.addAll(latin_alphabet_uppercase);
- allCharacters.addAll(punctuation_and_symbols_3);
- allCharacters.addAll(latin_alphabet_lowercase);
- allCharacters.addAll(punctuation_and_symbols_4);
- }
- public static List<char[]> getAllCharacters() {
- new CharacterTable();
- return allCharacters;
- }
- private static List<char[]> generateCharactersList(int firstCharacterCode, int lastCharacterCode) {
- List<char[]> list = new ArrayList<>(lastCharacterCode - firstCharacterCode);
- for (int i = firstCharacterCode; i <= (lastCharacterCode); i++) {
- list.add(Character.toChars(i));
- }
- return list;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement