How to create a simple e encryption and decryption program.

Write a program to do simple encryption and decryption. Encryption basically means to convert the
message into unreadable form. In this assignment, it should be done by replacing each letter of a message
with a different letter of the alphabet which is three positions further in the alphabet. Then, all the letters
will be reversed. Decryption is the process of converting encrypted message back into its original message.
Your program should use the following shifting method. Note: You must use array.


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
#include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
        string input;
        int count = 0, length;
        
        
        printf("Encryption\n");
	    printf("==========\n");
       
        cout << "Enter your phrase: \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 << "Results: \n" << input << endl ;
       
}



i need help on this guys =(
Last edited on
A few things

1) Post code here using the code tag
2) your "main" signature is not standard
3) You are using "printf" in a C++ program, though you have included <iostream> and using cout elsewhere
4) If you want to use string then

1
2
 for ( std::string::iterator it=input.begin(); it!=input.end(); ++it)
    std::cout << *it;

or
in C++11

1
2
for( auto it=input.begin(); it != input.end(); ++it )
    std::cout << *it;


is the way to go through it

5) Dont use string as you are required to used arrays. Use char[some_length].

If you dont know how to use arrays look here http://www.cplusplus.com/doc/tutorial/arrays/
Thanks for your reply!
Could you help me produce a code for this program and i will try to evaluate the whole thing from there?
Im in short time due to my operation and this is part of my assignment!

Thank you!
Topic archived. No new replies allowed.