Thread: Caesar Cipher

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    2

    Caesar Cipher

    I did a search before joining here but couldn't find anything relating to what I'm working on...
    I have to make a Caesar cipher program that enters a phrase (using getchar), then enters the shift amount and outputs the encrypted phrase. I need to make sure it "wraps around" as if the input letter was z, and shift was 3, it would turn into c. I also need to make sure to only shift letters, not punctuation.

    I have no idea how to even start basically, that's the only guidance I've got. We haven't gotten to strings so I have to use getchar somehow, or an array but I'm not sure how I would do that.

    Any advice or help would be greatly appreciated.

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Start with whatever you know so far. Generally assignments are there to test what you have learnt and maybe push you slightly.

    For this program you will need knowledge of things like input/output, loops and conditionals.

    These are usually the first few chapters of any C tutorial/book. If you have a more specific question we are happy to help you.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Usually Caesar Cipher is also used as an intro to cryptography and modular arithmetic, so I'm a little bit surprised that you couldn't find anything with just the keywords "Caesar Cipher" in your favourite search engine.

    Bye, Andreas

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You must be VERY unlucky in your search. They're all over, so you may want to try again.

    You should be using a char array[]. You can use getchar() to get the user's char, and then put it into the array. I strongly recommend you use a char array. You'll find it quite difficult to work with separate char variables in the program.

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    2
    I appreciate the responses, I was basically just looking for where to start I guess. I'll try the getchar and put that into the array. Thanks for the help though!

  6. #6
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    It doesn't matter how big the problem is, my advice is to research what is being asked of you.

    Your first stop should be wiki's Caesar cypher page.

    Think about how you could do this with a variable.
    Fact - Beethoven wrote his first symphony in C

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    There are no less than 17 pages listed on Google for Caesar cipher in C, but Wikipedia is always a good first step.

    And please, no more misstatements of the facts. We get enough of that from our politicians.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need help on what I think is a Caesar cipher......
    By CaesarCipher in forum C++ Programming
    Replies: 8
    Last Post: 11-28-2011, 04:13 PM
  2. Caesar Cipher help!!
    By darshan10 in forum C Programming
    Replies: 6
    Last Post: 10-19-2011, 04:58 PM
  3. Caesar Cipher
    By dldsob in forum C++ Programming
    Replies: 7
    Last Post: 07-06-2009, 06:06 PM
  4. Caesar Cipher
    By blacknapalm in forum C Programming
    Replies: 8
    Last Post: 11-13-2008, 12:11 AM
  5. Help with Caesar cipher
    By jcmichman in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2005, 10:50 AM