how to code a key to the encipher at decipher code?

this is the output

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
[E] encipher
[D] decipher
[X] Exit

Enter choice: e(user input)
Enter message to encrypt: (user input)
Enter key:user input)
The encrypted message:
Back to main menu?
(Yes/No) YES (return to menu if NO, program exits) : y (user input)

Enter choice:d(user input)
Enter message to decrypt:(user input)
Enter key:(user input)
The decrypted message is:
Back to main menu? (y/n): N (user input)


MY PROBLEM ARE HOW TO CREATE CODES FOR ENTER KEY,BACK TO MAIN MENU, why there exist a no. when the user type it. it should be A-Z only and also the spacing what the code for SPACING? PLEASE HELP..

THIS IS MY CODE. WHATS THE LACKING OF MY CODES?AM I PUT STRING PASSWORD?

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


#include <iostream >
#include <iomanip>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;

char getmenuselection (char m);
void encrypt (char key[]);
void decrypt (char code[]);


int main()
{
ifstream input;
ifstream in;
ofstream out;
char menu;
char file [80];
char codekey;
char myname[128];
menu=0;

menu=getmenuselection(menu); //Asks user what function to use.

if (menu == 'e' || menu == 'E') //Option to encrypt a file.
{
cout << "Enter message to encrypt:";
input.open (file);
cin >> file;
encrypt (file);
input.close();
cout << " The encrypted message is: " << file <<endl;
return main();
}
if (menu == 'd'|| menu == 'D')//Option to decrypt a file.
{
cout << "Enter message to decrypt: ";
input.open (file);
cin >> file;
decrypt (file);
input.close();
cout << "The decrypted message is: " << file <<endl;
return main();
}
if (menu == 'x'|| menu == 'X') //Option to end the program.
{
cin.ignore(1);
return 0;
}
cin.ignore(2);
return 0;
}
char getmenuselection (char m) //Menu selection function.
{
cout << "[E]encipher"<<endl;
cout << "[D]decipher"<<endl;
cout << "[X]Exit"<<endl;
cout << "Enter choice:";
cin >> m;
switch (m)
{
case 'e':
case 'E':
break;
case 'd':
case 'D':
break;
case 'x':
case 'X':
break;
default: cout << "Invalid entry, please try again... ";
return getmenuselection (m);
}return (m);
}
void encrypt (char key[]) //encryption function.
{
for(int i = 0; i < 5; i++) key[i] += 2;
}
void decrypt (char code[]) //decryption function.
{
for(int i = 0; i < 5; i++) code[i] -= 2;
}
Last edited on
Something along these lines:

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
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>

char getmenuselection()
{
    std::cout << "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\n"
                 "[E] encipher\n"
                 "[D] decipher\n"
                 "[X] Exit]\n"
                 "Enter choice: " ;

    char choice ;
    std::cin >> choice ;

    switch(choice)
    {
        case 'E': case 'e': return 'E' ;
        case 'D': case 'd': return 'D' ;
        case 'X': case 'x': return 'X' ;
        default:
            std::cout << "Invalid entry, please try again\n" ;
            return getmenuselection() ;
    }
}

int main()
{
    char sel ;

    do
    {
        sel = getmenuselection() ;

        switch(sel)
        {
            case 'D':
                std::cout << "decipher\n" ;
                // code for decipher ...
                break ;

            case 'E':
                std::cout << "encipher\n" ;
                // code for encipher...
                break ;

            case 'X' :
                std::cout << "exit\n" ;
                return 0 ;
        }

        char repeat ;
        std::cout << "Back to main menu? (y/n)? " ;
        std::cin >> repeat ;
        if( repeat != 'Y' && repeat != 'y' ) sel = 'X' ; // exit

    }
    while( sel != 'X' ) ;
}
yes MR. OUR PROBLEM IS THE CODE FOR ENCIPHER AND DECIPHER
Last edited on
Topic archived. No new replies allowed.