help for ceaser cipher program

May 27, 2013 at 5:38am
how does this program works ? can you explain step by step?

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 #include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    
    string input;
    
    int count =0, length;
    
    cout << "Enter your text:\n";
    
    getline(cin,input);
    
    length=(int)input.length();
    
    for (count =0; count < length; count ++)
    
    {
        if(isalpha (input[count]))
        
        { 
                   input[count]=tolower(input[count]);
          
                    for(int i = 0; i<13; i++)
                    {
                            if(input[count]=='z')
                              
                              input[count]='a';
                              
                              else
                              input[count]++;
                              
                              }
                      }    
                                      
             
             
             }
             
            cout <<"encrypted text:\n" << input << endl ; 
             
    
     system("PAUSE");
    return EXIT_SUCCESS;
}
May 27, 2013 at 6:35am
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    
    string input;
    
    int count =0, length;
    
    cout << "Enter your text:\n";
    
    getline(cin,input); // get a string from the user
    
    length=(int)input.length(); // calculate length of the string
    
    for (count =0; count < length; count ++) // loop through the entire string a character at a time
    
    {
        if(isalpha (input[count])) // if the character is alphabetical (a-z, A-Z)
        
        { 
                   input[count]=tolower(input[count]); // convert it to lowercase (a-z)
          
                    for(int i = 0; i<13; i++) // loop 13 times
                    {
                            if(input[count]=='z') // if the character is 'z'
                              
                              input[count]='a'; // set the character to 'a'
                              
                              else
                              input[count]++; // otherwise, increase the character by one ('a'->'b', 'c'->'d', etc)
                              
                              }
                      }    
                                      
             
             
             }
             
            cout <<"encrypted text:\n" << input << endl ; // output the altered string
             
    
     system("PAUSE");
    return EXIT_SUCCESS;
}
May 27, 2013 at 11:32am
thank you so much . now everything is clear
Topic archived. No new replies allowed.