Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Caeser cipher encryption program in C++ Language which takes a keyword.

ID: 3678444 • Letter: C

Question

Create a Caeser cipher encryption program in C++ Language which takes a keyword. The keyword will fill the first part of the shifted array. The remaining letters will fill the end of the array. It should look like:

Key= TOY

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

T

O

Y

A

B

C

D

E

F

G

H

I

J

K

L

M

N

P

Q

R

S

U

V

W

X

Z

You should have an interactive menu with the following options:

1 Enter Keyword //takes new keyword and re-aligns shifted array

2 Encrypt message//takes a message of 140 characters and encrypts message

3 Decrypt message//takes an encrypted message of 140 characters and decrypts it

4 Quit//exits program;

Use the copy function from the <cstring> library not the <algorithm> library. If you use the algorithm library you need to make a change in visual studios precompiler settings or you will get an error. You cannot assign arrays using the ‘=’ operator; only individual indices of the array can be assigned this way.

Take one case or the other for input. All Caps or all lowercase. You can use “toupper(<char>)” to set all letters to upper case

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

T

O

Y

A

B

C

D

E

F

G

H

I

J

K

L

M

N

P

Q

R

S

U

V

W

X

Z

Explanation / Answer

#include <iostream>
#include <string>
#include <ctype.h>
#include <cstring>
#include <stdio.h>
using namespace std;

int main()

{

   char alpha[26] = { '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' };
   char encrypt[26];
   char decrypt[26];
   int choice;
   int step;
   char plainText[140];

   for (int i = 0; i < 26; i++) {
       encrypt[i] = alpha[(i + 3) % 26];
       cout << alpha[(i + 3) % 26];
   }
   for (int i = 0; i < 26; i++)
       decrypt[encrypt[i] - 'A'] = alpha[i];

   while (1)

   {
       cout
               << " Enter your choice. 1 Enter Keyword 2 Encrypt message 3.Decrypt message 4.Quit"
               << endl;
       cin >> choice;
       switch (choice) {
       case 1:
           cout << "Please enter String : ";
           break;
       case 2:
           cout << "Please enter String to be encrypted : ";
           scanf("%s", plainText);
           cout << plainText;
           for (step = 0; step < strlen(plainText); step++) {
               if (65 <= plainText[step] && plainText[step] <= 90) {
                   plainText[step] = encrypt[plainText[step] - 'A'];
                   cout << encrypt[plainText[step] - 'A'] << " ";
               }
           }
           cout << "ASASAS " << plainText;
           break;
       case 3:
           cout << "Please enter String to be decrypted : ";
           cin >> plainText;
           for (step = 0; step < strlen(plainText); step++)
               if (65 <= plainText[step] && plainText[step] <= 90)
                   plainText[step] = decrypt[plainText[step] - 'A'];
           cout << plainText;
           break;
       case 4:
           return 0;
       }
   }
} //end main

Using this code you can encrypt and decrypt I am not able to get case 1 also if you enter string sepeareted by spcae that is also not handled it will pick the string before space.

Let me know if you need more modifications.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote