Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created March 4, 2013 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5084652 to your computer and use it in GitHub Desktop.
Save anonymous/5084652 to your computer and use it in GitHub Desktop.
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