Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,239 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,346 people online right now. Registration is fast and FREE... Join Now!




Caesar Cipher

 
Reply to this topicStart new topic

Caesar Cipher, I need help

Xian8706
20 Nov, 2007 - 08:49 PM
Post #1

New D.I.C Head
*

Joined: 20 Nov, 2007
Posts: 2


My Contributions
Hello everybody first timer here. Im in a C++ program and my teacher wants me to make a program that will make a caesar cipher, Im having a hard time trying to make one because that teacher isnt that good at all lol. From what ive learn i need to use string cc(string s, int shift) and string cd(string c, int shift). The first one is to turn the first sentence or word into the cipher and the second one decodes the cipher. I really need help if someone can help me. Thanks!!
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Caesar Cipher
20 Nov, 2007 - 09:15 PM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,869



Thanked: 53 times
Dream Kudos: 550
My Contributions
well please see the forum rules.

You may want to start by learning what the Ceasar Cipher is. The prorgam is not very hard at all. If you look about you can find lots of examples and lots of topics on the subject here at DIC.
User is offlineProfile CardPM
+Quote Post

Xian8706
RE: Caesar Cipher
21 Nov, 2007 - 06:56 AM
Post #3

New D.I.C Head
*

Joined: 20 Nov, 2007
Posts: 2


My Contributions
Yea ive seen some other forums about the ceasar cipher but it seems too far beyond my knowledge lol. Im a first timer learning with c++, and the teacher does not explain things in detail how and why certain things work so im in the dark. I know what the ceasar cipher is and it does sound pretty easy to make, but the actual making the program sucks. I know people cant do the program for me i just need some hints and clues to start off with.
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Caesar Cipher
21 Nov, 2007 - 11:01 PM
Post #4

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,869



Thanked: 53 times
Dream Kudos: 550
My Contributions
The idea is just to shift characters. So lets say lets say I wanted to shift by 5, then A becomes F, B becomes G, ... etc...

in the computer characters are repersented by numbers... for most part this is ASCII which, although an older standard, is the normal way to represent text data in a computer.

So when you type in an A the computer stores the number 65... 65+5=70 which is the code for F...

So to caesar cipher the string HELLO WORLD we get:
72 69 76 76 79 32 87 79 82 76 68 -> 78 74 81 81 84 32 92 84 81 73
HELLO WORLD -> NJQQT \TWQI

Note that the W turned into a symbol... this is a slight bug, but how to fix it? well basically we need to wrap the numbers at 91 -> 65. I would do this using the mod operator myself, but you can actually just use an if-statement.

if (cypherLetter > 'Z') { cypherLetter-=26; }

This makes:
72 69 76 76 79 32 87 79 82 76 68 -> 78 74 81 81 84 32 66 84 81 73
HELLO WORLD -> NJQQT BTWQI


If encryption is addition, then decryption is subtraction.

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/9/09 06:15AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month