public
anonymous / AlphaCipher Stats
Created

  • Download Gist
AlphaCipher Stats
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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();
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.