I know a few people here are Java programmers, and I need help with an assignment that has to be in on Monday. I've got the whole program planned out, I'm just having problems coding one specific part.
Basically, the project is based around decrypting various codes and ciphers, reading in the ciphertext from a plain-text file, decrypting it and displaying it to the user.
I have the decryption algorithm sorted:
1) Test word to see if it's in a pre-read dictionary
2a) If the word is found, continue until 5 (for example) lines have been tested, recording the "shift number".
2b) If the word isn't found, shift it one place to the right and loop back to 2a.
3) If the percentage of words correct is above 70%, then shift the rest of the ciphertext with the number of shifts taken to translate the ciphertext to readable English
Example:
Plaintext = HELLO
Ciphertext (shifted 1 place left) = GDKKN
Program does the following:
1) test "GDKKN" - not found
2) shift right one place and test "HELLO" - found
3) continue with rest with the shift "1 right"
I may be over-explaining stuff, but hey. All I need to do is read in the data file and transform it into a format that I can iterate over and test on a per-word basis (and ideally a per-line basis as well).
I've thought about using a two-dimensional String array, first dimension holding the line, second dimension holding each word - but I can't figure out a way to get from the data file to the array!
Example data file is here: http://pcbo.dcs.aber.ac.uk/Teaching/200 ... esar.crypt
Any help appreciated - I fucking hate Java!
Urgent: Java Programming Help Needed....
Moderators: James, Craig, Resilience Records
6 posts
• Page 1 of 1
Urgent: Java Programming Help Needed....
Personal Site | Freelance Web Design | Last.fm


Bash.org wrote:<Patrician|Away> what does your robot do, sam
<bovril> it collects data about the surrounding environment, then discards it and drives into walls
- Craig
Administrator
- Posts: 981
- Joined: Wed Mar 22, 2006 7:06 pm
- Location: Witham, Essex, UK
This confuses me. What do you want to store in the array? The position of the work and the coded word?
If you can read the word, why can you just store it in the array?
If you can read the word, why can you just store it in the array?

thrashduck wrote:Are you a small boy?
- Metalbrew Stu

- Posts: 1102
- Joined: Thu Jan 18, 2007 6:08 pm
- Location: North London
Me and my crap descriptions. What I've got is a file like the one I've linked to. I can read the lines of the file by setting up a FileReader and BufferedReader and calling readLine()...- Code: Select all
FileReader file = new Filereader("caesar.crypt");
BufferedReader buffer = new BufferedReader(file)
String line = buffer.readLine();
That will get me something like the following in one String:
VR VKH ZDV FRQVLGHULQJ LQ KHU RZQ PLQG (DV ZHOO DV VKH FRXOG,
I then need to split that into separate Strings for each word, which I know I can do by calling:
- Code: Select all
String [] words = line.split(" ");
I can then iterate over the words array. I don't know how many words are in the cipher text so I'll have to use a dynamic ArrayList. The problem comes when the ciphertext has lines like this:
- Code: Select all
GRZQ WKH UDEELW-KROH
i.e. lines with masses of whitespace. The split(" ") will pick up each whitespace. If I call split(" ") on the above line, I get an array with 25 entries for a line with three words.
Sorry if I'm not explaining things properly lol

Personal Site | Freelance Web Design | Last.fm


Bash.org wrote:<Patrician|Away> what does your robot do, sam
<bovril> it collects data about the surrounding environment, then discards it and drives into walls
- Craig
Administrator
- Posts: 981
- Joined: Wed Mar 22, 2006 7:06 pm
- Location: Witham, Essex, UK
lolz
thrashduck wrote:And the internet was without uk thrash form, and void; and darkness was upon the face of the deep. And the Spirit of James moved upon the face of the waters.
"No Hellscourger, I would not like a strawberry."
- James
Administrator
- Posts: 8334
- Joined: Wed Mar 22, 2006 6:17 pm
- Location: Witham, Essex
Ok, why not use the add() method of the ArrayList to add the String array of each line to the ArrayList, convert that to a String array using toArray(). Then you could write you own method to remove entries that are just " " and you're left with a String Array containing all the words in the file, yeah?
I'm probably getting the idea all wrong. Glad I don't do any of this anymore.
I'm probably getting the idea all wrong. Glad I don't do any of this anymore.

thrashduck wrote:Are you a small boy?
- Metalbrew Stu

- Posts: 1102
- Joined: Thu Jan 18, 2007 6:08 pm
- Location: North London
6 posts
• Page 1 of 1
