Computing.Net > Forums > Programming > Simple Java Programming Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Simple Java Programming Help

Reply to Message Icon

Name: Leo2k7
Date: November 29, 2003 at 23:09:02 Pacific
OS: Windows XP Pro
CPU/Ram: P4 2.6 gHz / 1 GB RAM / S
Comment:

I am making a decoder for a substitution cipher using frequency analysis (the num of times a letter pops up in a sentence, for example, 'E' is the most used letter, followed by 'T'). Anyways, I've got some of it working but I'm stuck on one part. I need to generate a new key based on the frequency analysis of the encoded sample.

Here's what I have:

//This method creates a new array of characters beginning with the most used letters from the sample.

public static char[] MakeAlphaKey(char[]Alphabet, int[]FrequencyKey)
{
char[] AlphaKey = new char[26];
for(int a = 0; a < 26; a++)
{
AlphaKey[a] = Alphabet[Max(FrequencyKey)];
}
return AlphaKey;
}

//Method to find most common letter
//I think the problem is somewhere in this method with maxindex, but I cant figure out what.
//FrequencyKey is a list of ints represented in Alphabetical order, so for example, FrequencyKey[0] = 5, which is the number of 'A's in the encoded text. FrequencyKey[1] is the number of B's.

public static int Max(int FrequencyKey[])
{
int max = 0;
int maxindex = 0;

for (int i = 0; i < 26; i++)
{
if(FrequencyKey[i] > max)
{
max = FrequencyKey[i];
maxindex = i;
FrequencyKey[i] = -1;
}
//Maybe add something here???
}
return maxindex;
}

Any help would be appreciated. I know how to do the rest of the program already. It's just this one part is really frustrating.




Sponsored Link
Ads by Google

Response Number 1
Name: Gagey
Date: November 30, 2003 at 19:56:19 Pacific
Reply:

Why do u set FrequencyKey[i] to -1 when u find a max candidate??

If it is so that it doesnt get picked up as the Max freq next time, then don't set it to -1 inside the loop, move it to just b4 u return the maxindex value.


0

Response Number 2
Name: Gagey
Date: November 30, 2003 at 19:58:23 Pacific
Reply:

Something like:

FrequencyKey[maxindex] = -1 ;
return maxindex ;

int the Max(int[]) method.


0

Response Number 3
Name: Leo2k7
Date: November 30, 2003 at 20:38:18 Pacific
Reply:

I love you guys :) :) :)


0

Response Number 4
Name: Leo2k7
Date: November 30, 2003 at 20:39:14 Pacific
Reply:

err just noticed it was the same guy =\ haha

Thanks a bunch.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Simple Java Programming Help

Please help with java program. www.computing.net/answers/programming/please-help-with-java-program/14834.html

Java Program Help www.computing.net/answers/programming/java-program-help/5365.html

need help w/ java programming www.computing.net/answers/programming/need-help-w-java-programming/9632.html