Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Ceasar Cipher

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ceasar Cipher

    I'm in an intro to programming class and while I'm able to follow along with basic problems, I totally don't get some of the problems that get assigned as homework. I've spent an inordinate amount of time trying to just figure out how to started on what I've come to realize (after looking at literally every google search possible related to this) is a very simple problem. I just don't know how to get the ball rolling here. I basically just need to make a program that takes a cipher inputted by the user and moves all the characters in that cipher "up" 3 characters [i.e. D (68 as I understand it is interpreted in computer language) goes to A (65)]. I realize it's supposedly really simple but I have literally no idea how to do it.

    Can someone give me like a pseudocode or something so I can see the basic framework? The full code would be great as well but I really want to wrap my head around this stuff and I think seeing it in a language I can actually understand might do a lot to help. Any and all assistance would be extremely appreciated.


  2. #2
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default

    No one will do it for you. And you will most likely be asked to have a fair go yourself before being offered assistance.

    Try writting out the steps yourself first. Post them up and ask direct questions. You will be more inclined to have someone offer their time when you show your own commitment.

    It is pretty easy and I'm sure we can get you there pretty quickly.

    Remember if you post actual code to use the appropriate formatting tags.

    You won't be ridiculed for trying.

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Ceasar Cipher

    Listen I understand the whole not wanting to do someone's homework sentiment. I just have no idea where to even start -- what classes, methods or whatever to use.

    If I had to write it in plain regular english it would simply be something that asked the user to input the encrypted cipher, then took that input, shifted each of the letters 3 places up individually, and then spit out the result. That simple. The problem is I don't know to design that letter-shift mechanism.

    Let me rephrase my question then: can someone show me how to write that letter shifting mechanism? Or, if that is too much to do, just give me the key java terms I would need so I can look them up in my textbook?

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Ceasar Cipher

    Quote Originally Posted by programnovice View Post
    something that asked the user to input the encrypted cipher, then took that input, shifted each of the letters 3 places up individually, and then spit out the result. That simple.
    Step 1: ask user for input
    Step 2: shift the input one character at a time
    Step 3: spit out the result

    Take the steps you have listed and refine them more and more, until they seem like such a simple task. When you focus on writing many codes to solve many small problems, you will no longer be trying to write one code to solve a big problem.
    When you get the steps broken down and run into a problem, post your steps, what you are stuck on, and what code you have so far with your question.

  5. #5
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default Re: Ceasar Cipher

    Okay, good one.

    String API 7, look at the method tochararray(). It basically takes a string and explodes it into an array of chars. Once you have those, manipulation becomes easier.

    Run this in your IDE and understand what is happening. See what you can come up with.

    public class Sandbox {
     
        public static void main(String[] args) {
     
            //Initial string
            String hello = "Hello";
     
            // Explode the string into an array of chars
            char[] charArray = hello.toCharArray();
     
            // Print the array as a string
            System.out.println(String.valueOf(charArray));
     
            // Print each character of the array
            for (int i = 0; i < charArray.length; i++) {
                System.out.print(charArray[i] + ", ");
            }
     
        }
    }

  6. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Ceasar Cipher

    Quote Originally Posted by programnovice View Post
    I just have no idea where to even start
    The number of people who say that is starting to pi$$ me off.
    class CaesarCipher {
     
    }
    That is a start. If you still whine that you cannot even do that then quit. Otherwise continue to build on that. Add a main method. Add a single char variable that holds a value. Add a print statement that outputs the cipher version of that char. etc etc etc. At each stage compile and run you code to make sure it works before proceeding.
    Improving the world one idiot at a time!

  7. #7
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: Ceasar Cipher

    Hello.
    Based on your writing the only solution is to give you a ready-made program.
    Otherwise you need to learn java step by step and write your program.
    In my opinion its very hard to give you any starting point.

    Syed.

Similar Threads

  1. Replies: 1
    Last Post: May 22nd, 2013, 07:48 PM
  2. PLEASE Help With Ceasar Cipher Program!!
    By Jstew2408 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 25th, 2011, 12:23 AM
  3. Cipher Program - Not sure what this error is - PLEASE HELP
    By Jstew2408 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: October 24th, 2011, 11:27 PM
  4. Cipher Program
    By Shyamz1 in forum Object Oriented Programming
    Replies: 2
    Last Post: September 20th, 2011, 04:11 PM
  5. [SOLVED] Interesting error cipher while sending message
    By Koren3 in forum Java Networking
    Replies: 0
    Last Post: April 29th, 2009, 09:54 AM

Tags for this Thread