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

Problem Instructions Write a program that can \"encrypt\" a word using a Caesar

ID: 3632838 • Letter: P

Question

Problem Instructions

Write a program that can "encrypt" a word using a Caesar cipher (shifting a character K distance away). You are essentially manipulating the ASCII value for each character. To "encrypt", simply just add K to the character value. Restrict the valid range to be human readable characters (i.e. ASCII values between 32 and 126, inclusively). The program should allow the user to "encrypt" multiple words.

**Example:**

Cryptography program!!!
Input a shifting distance that's less than 10: 2
Input a word: Hello

Encrypted word is:
Jgnnq

Do you still want to continue?[y/n]: y
Input a word: World

Encrypted word is:
Yqtnf

Do you still want to continue?[y/n]: N

Explanation / Answer

//header files

#include<iostream>

#include<string>

using namespace std;

//main function

int main()

{

       //variable declaration

       int distance,i,len;

       char choice;

       string word;

       //prompting user for input

       cout<<"Cryptography program!!!"<<endl;

       cout<<"Input a shifting distance that's less than 10: ";

       cin>>distance;//reading key

       do

       {

              //reading word.

              cout<<"Input a word: ";

              cin>>word;

              i=0;

              len = word.length();

              //encrypting

              while(i<len)

              {

                     word[i]=word[i]+distance;

                     i++;

              }

              //displaying encrypted word

              cout<<"Encrypted word is:"<<endl;

              cout<<word<<endl;

              //ask for continuing

              cout<<"Do you still want to continue?[y/n]: ";

              cin>>choice;

              choice=tolower(choice);

       }while(choice=='y');

       system("pause");

       return 0;

}//end of main

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