Encryption and Decryption

Question:

A company wants to transmit data over the telephone. All of their data is transmitted as 4-digit integers. You will write a program that encrypts and decrypts their data so that it may be transmitted more securely. Your program should ask the user which operation he/she wants to do. The user may choose to encrypt (E or e) or decrypt (D or d) the integer he/she will input, or quit (Q or q) the program. If the user chooses to encrypt or decrypt an integer, the program will ask the user to input a 4-digit integer.

In your program use four functions: Function menu() displays the menu as given in the sample run, gets user input until user inputs a valid operation code. It will return the operation code to the calling function through a parameter. Function encrypt() receives an integer value, encrypts it and returns the result under function name. Function decrypt() receives an integer value as a parameter and returns its decrypted form by a parameter to the calling function. main() function will perform the other required tasks.
**********************************************************************************************************************
Encryption process will be as follows:

Replace each digit of the integer input by <the sum of that digit plus 7> modulus <10>. That is,

(digit + 7) modulus 10.

For example, if 4617 is input as integer number to be encrypted,

(4 + 7) modulus 10 = 1
(6 + 7) modulus 10 = 3
(1 + 7) modulus 10 = 8
(7 + 7) modulus 10 = 4

encrypted integer will be 1384.
**********************************************************************************************************************
Decryption process will recover the original form of the encrypted integer from the decrypted integer.

For example, if 1384 is input as integer number to be decrypted, the decrypted integer will be 4617. In other words, you have to reverse the encryption process to find decrypted integer. (Think about it!)
**********************************************************************************************************************
Your program will ask the user if he/she wants to encrypt / decrypt another integer after encrypting / decrypting the integer and continue the process until user wants to stop inputting integers.

When the user wants to stop the encryption / decryption process, your program will return to the main menu, ask the user what he/she wants to do again and continue to execute until user chooses to quit the program.

You should consider all possible inputs; that is, capital and lowercase character inputs, wrong operation codes, integers that don
This is what i wrote so far. There are missing parts.



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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

char menu (char );
int encrypt ( int );
int decrypt ( int );



int main ()
{
char a; // identified a character to execute the menu func.
cout << "**************************************" << endl;
     cout << "* Integer Encryption/Decryption Tool *" << endl;
     cout << "**************************************" << endl << endl ;
     cout << "(E/e) Encryption" << endl;
     cout << "(D/d) Decryption" << endl;
     cout << "(Q/q) Quit" << endl;
menu (a); // menu func starts here.
system ("Pause");
return 0;
    
}

char menu ( char x )
{
     int a;
     char code; // code is the character that user will input
     cout << "Enter operation code: ";
     cin >> code;
     if ( code == 'e' || code == 'E') 
          encrypt(a);
     else if ( code == 'd' || code == 'D' )
          decrypt(code);
     else if ( code == 'q' || code == 'Q' )
          cout << "Bye!" << endl;
     else { 
          cout <<  "You entered an invalid operation code!" << endl;
          menu('X');
          }       
}

int encrypt (int a) 
{
    cout << "**********************" << endl << "* Encryption Process *" << endl << "**********************" << endl << endl << "Enter the 4-digit integer to be encrypted : ";
     int digit,b;
     char cont;
     cin >> digit;
     int bas1,bas2,bas3,bas4;
     if ( 999 < digit < 10000 ) {
          bas1=digit/1000;
          bas2=digit/100 - 10*bas1;
          bas4= digit%10;
          bas3= (digit%100 -bas4)/10;
          cout << "Encrypted integer is " << (bas1+7)%10 << (bas2+7)%10 << (bas3+7)%10 << (bas4+7)%10 << "." << endl;
          
              }
     else {
          cout << "You entered an invalid integer!" << endl;
          encrypt(digit);
          }
}

int decrypt ( int a) 
{
    cout << "**********************" << endl << "* Decryption Process *" << endl << "**********************" << endl << endl << "Enter the 4-digit integer to be decrypted : ";
    int digit,c;
    cin >> digit;
    int bas1,bas2,bas3,bas4;
     if ( 999 < digit < 10000 ) {
          bas1=digit/1000;
          bas2=digit/100 - 10*bas1;
          bas4= digit%10;
          bas3= (digit%100 -bas4)/10;
          cout << "Decrypted integer is " << (bas1+3)%10 << (bas2+3)%10 << (bas3+3)%10 << (bas4+3)%10 << endl;
          }
     else {
          cout << "You entered an invalid integer!" << endl;
          decrypt(1234);
          }
}


Last edited on
For char menu(char x) you never return anything, and you never use the variable x. Same with all the other functions.
Last edited on
... ^:)^ sorry before ...
Last edited on
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
sorry for bad english .. i try to fix !!

#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
using std::cin;
using std::cout;
using std::endl;

char menu (char );
int encrypt ( int );
int decrypt ( int );

int main ()
{
char a; // identified a character to execute the menu func.
cout << "**************************************" 
<< endl;
     cout << "* Integer Encryption/Decryption Tool *" << endl;
     cout << "**************************************" 
<< endl << endl ;
     cout << "(E/e) Encryption" << endl;
     cout << "(D/d) Decryption" << endl;
     cout << "(Q/q) Quit" << endl;
menu (a); // menu func starts here.
return 0;
    
}

char menu ( char x )
{
     int a;
     char code; // code is the character that user will input
     cout << "Enter operation code: ";
     cin >> code;
     if ( code == 'e' || code == 'E') 
          encrypt(a);
     else if ( code == 'd' || code == 'D' )
          decrypt(code);
     else if ( code == 'q' || code == 'Q' )
          cout << "Bye!" << endl;
     else { 
          cout <<  "You entered an invalid operation code!" << endl;
          menu('X');
          }       
}

int encrypt (int a) 
{
    cout << "**********************" 
<< endl << "* Encryption Process *" << endl
 << "**********************" << endl 
<< endl << "Enter the 4-digit integer to be encrypted : ";
     int digit,b;
     char cont;
     cin >> digit;
     int bas1,bas2,bas3,bas4;
     if ( 999 < digit < 10000 ) {
          bas1=digit/1000;
          bas2=digit/100 - 10*bas1;
          bas4= digit%10;
          bas3= (digit%100 -bas4)/10;
          cout << "Encrypted integer is " 
<< (bas1+7)%10
<< (bas2+7)%10 
<< (bas3+7)%10 
<< (bas4+7)%10 
<< "." << endl;
          
              }
     else {
          cout << "You entered an invalid integer!" 
<< endl;
          encrypt(digit);
          }
}

int decrypt ( int a) 
{
    cout << "**********************" << endl 
<< "* Decryption Process *" << endl 
<< "**********************" << endl << endl 
<< "Enter the 4-digit integer to be decrypted : ";
    int digit,c;
    cin >> digit;
    int bas1,bas2,bas3,bas4;
     if ( 999 < digit < 10000 ) {
          bas1=digit/1000;
          bas2=digit/100 - 10*bas1;
          bas4= digit%10;
          bas3= (digit%100 -bas4)/10;
          cout << "Decrypted integer is " << (bas1+3)%10 
<< (bas2+3)%10 
<< (bas3+3)%10 
<< (bas4+3)%10 
<< endl;
          }
     else {
          cout << "You entered an invalid integer!" << endl;
          decrypt(1234);
return 0;
}
}
Last edited on
Topic archived. No new replies allowed.