public void quiz1_q1() { FileResource fr = new FileResource("../secretmessage1.txt"); String encrypted = fr.asString(); int[] key = new int[4]; key = tryKeyLength(encrypted, 4, 'e'); for (int i = 0; i < 4; i++) { System.out.println(key[i]); } }
public void testTryKeyLength() { FileResource fr = new FileResource("athens_keyflute.txt"); String encrypted = fr.asString(); int[] key = new int[5]; key = tryKeyLength(encrypted, 5, 'e'); for (int i = 0; i < 5; i++) { System.out.println(key[i]); } }
public void breakVigenere() { // read in the encrypted message FileResource fr = new FileResource(); String encrypted = fr.asString(); // read in the dictionary of valid words FileResource dictRes = new FileResource("dictionaries/English"); HashSet<String> dict = readDictionary(dictRes); String decrypted = breakForLanguage(encrypted, dict); System.out.println(decrypted); }
public void testBreakForAllLanguages() { // read in the encrypted message FileResource fr2 = new FileResource("athens_keyflute.txt"); String encrypted = fr2.asString(); HashMap<String, HashSet<String>> myMap = new HashMap<String, HashSet<String>>(); FileResource fr = new FileResource("dictionaries/English"); HashSet<String> dict = readDictionary(fr); myMap.put("English", dict); FileResource fr1 = new FileResource("dictionaries/Spanish"); HashSet<String> dict1 = readDictionary(fr1); myMap.put("Spanish", dict1); breakForAllLanguages(encrypted, myMap); }
/* * method to return a HashSet of words lower-cased and read from the file * passed in as a parameter */ public HashSet<String> readDictionary(FileResource fr) { // create a HashSet which you will be returning HashSet<String> dict = new HashSet<String>(); for (String line : fr.lines()) { // convert to lowercase and add to the dictionary line = line.toLowerCase(); dict.add(line); } return dict; }