Results 1 to 4 of 4
- 01-20-2009, 06:52 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
Need help with Ceasar Cipher question
here's the original question
ecoo.org/ecoocs/boardwide/brd2004p2.html
basically the program needs to read paragraphs from the file
(which are encrypted with ceasar cipher algorithm), and when it sees (***) it has to stop and promote a user to enter any key to continue the decrypting. I only gotten to the point where the user enters his own string which then is being decrypted and the decrypted word is displayed( and even this gives me an error).
Can please anybody with some advanced java knowledge figure this out ? any help will be appreciated.
and btw, here's what I did so far
Java Code:import java.util.Scanner; public class Problem2CeasarCipher { public static void main(String[] args) { Scanner input = new Scanner(System.in); char[] wordLetters; int[] letterCounts = new int[26]; int arrayIndex; int offset; int tempIndex = 0; int tempHighest = 0; System.out.println("Enter a sentence: "); String sentence = input.nextLine(); String copySentence = sentence; sentence = sentence.replaceAll(" ", ""); wordLetters = sentence.toCharArray(); for(int letter = 0; letter < wordLetters.length; letter++) { offset = wordLetters[letter] - 65; letterCounts[offset] +=1; } for(int i = 0; i <= 25; i++) { if (letterCounts[i] > tempHighest) { tempHighest = letterCounts[i]; tempIndex = i; } } testProblem2CeasarCipher encoding = new testProblem2CeasarCipher(tempIndex); encoding.decode(copySentence); System.out.println(encoding.decode()); } } ///////////// public class testProblem2CeasarCipher { int e = 4; int shift; int move; public testProblem2CeasarCipher(int mostFrequent) //costructor with an array parameter { shift = mostFrequent - e; move = 26 - shift; } public String decode(String word) { StringBuffer result = new StringBuffer(); for (int k = 0; k < word.length(); k++) { char ch = word.charAt(k); ch = (char)('A' + (ch - 'A' + move) % 26); result.append(ch); } return result.toString(); } }
- 01-21-2009, 03:11 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You want to know how to decryption work on with Java?
- 01-21-2009, 03:14 AM #3
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
never mind, check my another thread in this forum, I already working on it
- 01-21-2009, 03:25 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Please don't ask the same question in different sub-forums, sick on one.
Similar Threads
-
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM -
cipher.. Won't work
By jgonzalez14 in forum New To JavaReplies: 1Last Post: 11-18-2008, 01:22 PM -
question
By ayoood in forum Java SoftwareReplies: 6Last Post: 07-07-2008, 01:32 PM -
Question
By ayoood in forum New To JavaReplies: 16Last Post: 05-21-2008, 02:23 PM -
JSP Question
By maheshkumarjava in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 03-29-2008, 10:51 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks