I am building this algorithm as part of a larger project for a network security class. The gist of this part is that I have been given a dictionary, and I need to find every possible option for a word in both upper and lowercase.
My teacher selected a word out of this dictionary, and messed with the case of a few random letters in it, then created the SHA-256 hash value for it. We have been given the hash value and now have to find the word.
I figured I would create two new dictionaries, use the first one to create all possible options of the upper lowercase combinations, then use that second one to create a third with all the hash values.
Example:
to tO To TO
My first thought was that it looked a lot like counting in binary, and that's what I have based this algorithm off of. The only problem is that it's pretty slow.
public class DictionaryBuilder {
private Scanner in;
private PrintWriter out;
public DictionaryBuilder() {
}
public File createHashDictionary(File dictionary) throws IOException {
File hashDict = new File("HashDictionary.txt");
in = new Scanner(dictionary);
out = new PrintWriter(hashDict);
String word;
String wordList[];
while (in.hasNext()) {
wordList = getSmallWordList(in.nextLine());
for (int i = 0; i < wordList.length; i++) {
out.println(wordList[i]);
}
}
in.close();
out.close();
return hashDict;
}
public String[] getSmallWordList(String _word) {
System.out.println(_word);
char[] word = _word.toCharArray();
int length = (int) (Math.pow(2, _word.length()));
char[][] binaryList = new char[word.length][length];
int weirdCount = length / 2;
for (int i = 0; i < word.length; i++) {
//System.out.println();
int count = 0;
int onOff = 1;
for (int n = 0; n < length; n++) {
if (count == weirdCount) {
onOff++;
count = 0;
}
if ((onOff % 2 == 0)) {
binaryList[i][n] = Character.toLowerCase(word[i]);
System.out.print(binaryList[i][n]);
count++;
} else {
binaryList[i][n] = Character.toUpperCase(word[i]);
//System.out.print(binaryList[i][n]);
count++;
}
}
weirdCount = weirdCount / 2;
}
//System.out.println();
//System.out.println();
String wordList[] = new String[length];
for (int i = 0; i < wordList.length; i++) {
wordList[i] = "";
for (int n = 0; n < word.length; n++) {
wordList[i] = wordList[i] + "" + binaryList[n][i];
}
if(i%10==0){
System.out.println(wordList[i]);}
}
return wordList;
}
Main method:
public class Launch {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws NoSuchAlgorithmException, IOException {
File dictionary = new File("Dictionary");
DictionaryBuilder build = new DictionaryBuilder();
File x = build.createHashDictionary(dictionary);
Scanner in = new Scanner(x);
System.out.println(in.nextLine());
}
It's stuck on "Antidisestablishmentarian." Can I streamline this?
looked a lot like counting in binary- great. Now, what does take a significant amount of time? Can you re-use the result of one time-consuming step? What if you could? (Think about the S in SHA and what cryptographic hash functions are used for/dreamt up to be.) \$\endgroup\$