Results 1 to 4 of 4
  1. #1
    Gigi is offline Member
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Lightbulb 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();
      }
     
    }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Gigi is offline Member
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Default

    never mind, check my another thread in this forum, I already working on it

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 09:49 AM
  2. cipher.. Won't work
    By jgonzalez14 in forum New To Java
    Replies: 1
    Last Post: 11-18-2008, 02:22 PM
  3. question
    By ayoood in forum Java Software
    Replies: 6
    Last Post: 07-07-2008, 02:32 PM
  4. Question
    By ayoood in forum New To Java
    Replies: 16
    Last Post: 05-21-2008, 03:23 PM
  5. JSP Question
    By maheshkumarjava in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-29-2008, 11:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •