Results 1 to 3 of 3
Thread: Coded Message... Help Please
- 05-03-2009, 08:00 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 19
- Rep Power
- 0
Coded Message... Help Please
I have a code that I need help with...
------
Write a program that decodes secret messages read from a text file using an "alphabetic shift." So, for example, a shift might appear as:
ORIGINAL ABCDE...XYZ
SHIFTED. CDEFG...ZAB
You must:
1.) Read the encoded message from the attached MessageIn.txt file,
2.) Count the instance of each character in the file,
3.) The most common character in the message should be an "E". Use this information to calculate the amount of the shift,
4.) Print out the decoded message.
----
here is what i have to work with...
the code that needs to be decoded:
HVWGWGHVSPSGHQCADIHSFSLSFQWGSWVOJSSJSFSLDSFWSBQSR
I have figured out that:
char A in the message (encoded)= M (decoded);
char B = N;
char C = O;
char D = P;
char E = Q;
char F = R;
char G = S;
char H = T;
char I = U;
char J = V;
char K = X;
char L = W;
char M = Y;
char N = Z;
char O = A;
char P = B;
char Q = C;
char R = D;
char S = E;
char T = F;
char U = G;
char V = H;
char W = I;
char X = J;
char Y = K;
char Z = L;
----
I just need help finding out how to write it in java code... also here is what else I have to work with:
:confused:
public class test
{
public static void main(String args[])
{
//Method Number 1 using indexing
String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i = alpha.indexOf("G");
//Method Number 2 using chars and ASCII values
int j = (int)alpha.charAt(6) - (int)'A';
System.out.println(i+" "+j);
}
}
-
You may wish to let Java do the figuring out for you. If it were me, I'd create a 26 item array of ints (I'd probably actually use a Map, but you haven't learned that yet, I'll bet), and use simple char math to count the number of times a char is present.
For instance
Java Code:// semi-pseudo code int[] charArray = new int[26]; String inputString = // get input String from file... loop through every char in the input String char currentChar = inputString.charAt(i); int indexNumber = currentChar - 'A'; charArray[indexNumber]++; // adds 1 end Loop
Last edited by Fubarable; 05-03-2009 at 08:22 PM.
-
Similar Threads
-
Matrix Message
By shindry in forum New To JavaReplies: 2Last Post: 05-04-2009, 04:32 AM -
Scroll message
By getkiran in forum Java AppletsReplies: 1Last Post: 03-05-2009, 04:29 AM -
Color coded code
By tim in forum Suggestions & FeedbackReplies: 11Last Post: 06-29-2008, 09:35 AM -
Please wail Message in jsp
By amar.java in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 04-02-2008, 12:29 PM -
simulate message box
By pablitohh in forum New To JavaReplies: 1Last Post: 12-05-2007, 04:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks