Skip to content

anonymous /AlphaCipher Stats
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.