ceasers cipher

Pages: 12
this is my code so far i want to make it encrypt the cod by move the letters 2 spots to the left on the alphabet how do i do this.i want to make it simple.

#include <iostream>
#include <string>

using namespace std;

int main(){
char question[] = "enter a password you want to encypt,it has to be only letters";
char password[60];
cout << question;
cin >> password;

system("pause");
return 0;

}
can someone please help
take each char in turn.

make it lower case.

subtract 2 from each char

if the char value is now less than 97, add 26 to it.

move on to next char
can you please explain that to me.i dont really get what you mean
make it lower case.
c = tolower(c);

subtract 2 from each char
c= c-2;

if the char value is now less than 97, add 26 to it.
1
2
if c<97
{c = c+26}
im new to c++ so i dont get what you are syaing.ok here i go.
so i have char password[60]; does that mean like do 60 c -2's.. can you like please explain the format to me

and what does this mean c = tolower(c);

and where did you get 97 and 26 from
and what does this mean c = tolower(c);

Look it up. It's a standard C function.

Use a proper C++ string so you don't have to worry about putting a zero at the end of it.

97 because the letter 'a' in ascii is represented by a char with the numerical value 97. 26 because there are 26 letter in the alphabet. Experiment with this code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <cstring>
#include<string>

using namespace std;

int main()
{

  string c;

 cin >> c; // the password

 for (int i = 0; i<c.size();i++)
{
  c[i] =  tolower(c[i]);
  c[i]= c[i]-2;
  if (c[i]<97)
    {c[i] = c[i]+26;}
}

 cout << c << endl
 return 0;
}
Last edited on
Thx what does [I] mean
You are not ready for this level. You should at least work through the entire tutorial.

The specific part of the tutorial you need is:
http://www.cplusplus.com/doc/tutorial/arrays/
Ok but can you please tell me what [I] means
Thx what does [I] mean


No offense but your questions are SO basic that I have to provide the obligatory link: http://cplusplus.com/doc/tutorial/

Please read through it so you won't need quite so much hand-holding. ;-)

BTW, I'm not trying to be mean and I'm sure Moschops doesn't need me protecting him. I just want you to know there are resources you can access yourself instead of posting every little question and waiting for a response.
Ok I already did the tutorial up to character sequences
Please just tell me what [I] means,please
In an array, c[i] means *(c+i)
why does the program need the variable i
and when i compile this why does it have an error on the underlined line

#include <iostream>
#include <cstring>
#include <srting>
using namespace std;

int main()
{
string c;
cin >> c;
for (int i = 0; i<c.size();i++)
{
c[i] = tolower(c[i]);
c[i] = c[i]-2;
if (c[i]<97)
{c[i] = c[i]+26;)
}
cout << c << endl;
system("pause");
return 0;
}
Oh for crying out loud. What's the difference between a } and a ) ?
Last edited on
o gosh sorry...u make me feel stupid
ok now theres an error on the same line

#include <iostream>
#include <cstring>
#include <srting>
using namespace std;

int main()
{
string c;
cin >> c;
for (int i = 0; i<c.size();i++)
{
c[i] = tolower(c[i]);
c[i] = c[i]-2;
if (c[i]<97)
(c[i] = c[i]+26;)
}
cout << c << endl;
system("pause");
return 0;
}
{c[i] = c[i]+26;}

I'm done.
Ok I already did the tutorial up to character sequences
Please just tell me what [I] means,please


Hmmm, if you read (and understood) the tutorial up to character sequences you should have a grasp of control structures and arrays. [i] is simply the common variable name when it's used to index an array. In the tutorial an [n] is used instead. Re-read that section with that in mind and see if it starts to click.
im sorry mochops i just realized how annoying i was being
Pages: 12