Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Brute force generator for different types of charsets
public class StringBruteForceGenerator {
public static final char[] CYRILLIC_CHARSET = "абвгдеєжиіїйклмнопрстуфхцчшщьюя".toCharArray();
private char[] charset;
public StringBruteForceGenerator(final char[] charset) {
this.charset = charset;
}
public void generate(final int startLength, final int endLength,final Consumer<String> stringConsumer) {
for (int length = startLength; length < endLength; length++) {
generate("", length, stringConsumer);
}
}
private void generate(final String str, final int length, final Consumer<String> stringConsumer) {
if (length == 0) {
stringConsumer.accept(str);
} else {
for (final char c : charset) {
generate(str + c, length - 1, stringConsumer);
}
}
}
public static void main(final String[] args) {
final StringBruteForceGenerator stringBruteForceGenerator = new StringBruteForceGenerator(StringBruteForceGenerator
.CYRILLIC_CHARSET);
stringBruteForceGenerator.generate(5, 10, System.out::println);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment