I need help on what I think is a Caesar cipher......

This is a discussion on I need help on what I think is a Caesar cipher...... within the C++ Programming forums, part of the General Programming Boards category; Hello , I have a problem with my assignment problem , which I think is a caesar cipher The objective ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    2

    I need help on what I think is a Caesar cipher......

    Hello , I have a problem with my assignment problem , which I think is a caesar cipher

    The objective of my program is to encrypt/decrypt

    The program will take in a user in put as a keyword
    The letters of the alphabets are arranged starting with the keyword and followed by the remaining letters in reverse order
    The keyword will not have recurring letters.

    Using tiger as a keyword :



    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
    T I G E R Z Y X W V U S Q P O N M L K J H F D C B A

    I am supposed to use that to encrypt/decrypt messages
    But I am unsure of the logic , what will I use to arrange the letters ? what will I use to eliminate recurring alphabets.

    Thank you for the time.
    Last edited by CaesarCipher; 11-23-2011 at 07:59 PM.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,770
    Announcements - General Programming Boards

    This site expects the posters to write some code at least; read the URL above.

    Note: I am only a C programmer; so, I can not even help you if I wanted to do so.
    Note: If you already know how to sort array you might wish to think of the problem as an array sorting problem.

    Another link that might help you.
    C, C++ Programming Tutorials - Cprogramming.com

    Tim S.

  3. #3
    ...and never returned. StainedBlue's Avatar
    Join Date
    Aug 2009
    Posts
    168
    Perhaps an array of structs where each struct holds an encrypt char and a decrypt char. For example, your first struct in the array would contain 'A' for the decrypt char and 'T' for the encrypt char, and so on and so forth. As far as not allowing duplicate letters in the keyword, that's a matter of validating the user input; read the chars into a map, and if if the insertion fails (since maps dont allow duplicate keys) you know you have a duplicate letter. A map is also a good choice as an alternative to the encrypt/decrypt array i described previously. Obviously, you and your professor
    Know which c++ features you're allowed to use, so i leave it to you to pick the solution that meets those requirements

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    Do you know the length of the keyword? This is not a Caeser Cipher, that would be a simple substitution cipher eg , a = z, b = y, c = x etc. the problem is a hybrid and according to your rules you should basically ignore the substitution part of the cipher becuase once you have the keyword then the rest will follow. So given that computers are rather useful in repeating millions of mindless tasks, , your attack in this case should be to simply test sequences of abcde,(depending on what you think key length is..) over the whole ciphertext, then bcdef, then cdefg, etc etc, its a loop the loop, if the output reveals a sensible word... like t ig e r ' then you can start making assumptions, to be honest, if the output revealed a good word as long as 'tiger' then its a fair safe bet you have it cracked.

    But of course, you will need some code to do these test to start with.. so best get cracking eh ;-> show some effort and then you will get some good advice back.
    Last edited by rogster001; 11-24-2011 at 01:31 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    or maybe thats the other way around.. its a while since i looked at any
    cryptohydroponic analysis
    Last edited by rogster001; 11-24-2011 at 02:16 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  6. #6
    Registered User modwind's Avatar
    Join Date
    Dec 2010
    Posts
    15
    rogster001, this IS a Caeser Cipher.

    That task is not hard. You should use 2 arrays of chars:
    Code:
    char plaintext[26];
    char cypher[26];
    Fill the first one with A-Z.
    Start to fill the second one by adding the keyword TIGER. Then append letters Z-A one by one, checking if they appear in keyword.

  7. #7
    Registered User
    Join Date
    Nov 2011
    Posts
    2
    Hello , thank you for your input , everyone .

    The cipher key is user defined , which means that it could be 26 letters long , as long as does not have any recurring letters.

    I have thought of the logic of this question, but I have one problem :

    Can I shift text around ?

    I am planning to make my program check for matching letters between the text array and my cipher key , then bringing the cipher key to the front , and the rest at the back

    For example :

    using tiger as an example

    Text array='Z','Y','X','W','V','U','T','S','R','Q','P', 'O','N','M','L','K','J','I','H','G','F','E','D','C ','B','A'

    The program will search for T,I,G,E,R and bring it to the front.

    I will then shift the others to the back.

    Is there any C++ function that can aid me in this ?


    To any mods : I am not requesting for codes , good sirs , I am here just to ask questions .....

  8. #8
    Registered User
    Join Date
    Jul 2011
    Location
    Bangalore,India
    Posts
    24
    You can have two arrays like

    Code:
    char plaintext[26];
    char ciphertext[26];
    plaintext containing all alphabets...u could write a loop and use ASCII values...

    Have a string to take the keyword

    First add all alphabets of keyword to ciphertext array...
    then write a nested loop

    First one to traverse from index 25 to 0 of plaintext...
    Second to check if the index of plaintext is present in the keyword..set a flag if present...on exit of this loop u an check the flag and set the value for ciphertext if the flag is not set....

  9. #9
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    I don't agree that this is a classic ceaser cipher, as i said it is a hybrid, an evolution of the classic idea in a rudimentary attempt at greater security, which am sure is just one of the evolutions and refinements seen in the history of ciphers, but the point is moot.
    Last edited by rogster001; 11-28-2011 at 04:17 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Caesar Cipher help!!
    By darshan10 in forum C Programming
    Replies: 6
    Last Post: 10-19-2011, 05:58 PM
  2. Caesar Cipher
    By dldsob in forum C++ Programming
    Replies: 7
    Last Post: 07-06-2009, 07:06 PM
  3. Another Caesar Cipher
    By Swordsman in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2007, 09:56 AM
  4. caesar cipher help.
    By stormfront in forum C Programming
    Replies: 36
    Last Post: 11-22-2005, 08:45 PM
  5. Help with Caesar cipher
    By jcmichman in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2005, 11:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21