Created
March 4, 2013 19:17
-
-
Save anonymous/5084652 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AlphaCipher { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
// TODO code application logic here | |
if (args.length != 1) { | |
System.out.println("No Wordlist provided"); | |
} | |
String[] words = new String[0]; | |
try { | |
FileInputStream fis = new FileInputStream(args[0]); | |
Scanner s = new Scanner(fis).useDelimiter("\\A"); | |
String wordList = s.hasNext() ? s.next() : ""; | |
words = wordList.split("\\n"); | |
} catch (Exception e) { | |
} | |
for (int x = 0; x < 6; x++) { | |
printStats(words, x); | |
} | |
} | |
private static void printStats(String[] words, int position) { | |
int[] charFreq = new int[26]; | |
for (int x = 0; x < words.length; x++) { | |
charFreq[words[x].charAt(position) - 97]++; | |
} | |
for (int y = 0; y < 26; y++) { | |
int maxFreq = 0; | |
int maxChar = 0; | |
for (int x = 0; x < 26; x++) { | |
if (charFreq[x] > maxFreq) { | |
maxFreq = charFreq[x]; | |
maxChar = x; | |
} | |
} | |
charFreq[maxChar] = -1; | |
System.out.print(" " + (char) (maxChar + 97) + " "); | |
} | |
System.out.println(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment