1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
jekas [21]
3 years ago
13

Today we will be making a Caesar Cipher to encrypt and decrypt messages.A Caesar Cipher is a simple cipher that translates one l

etter to another via shifting the letter a few spaces in the alphabet. For example:A Caesar Cipher with a shift of 3 would turn A into D, B into E, C into F, and so on.Your task is to use string methods and two user defined functions (an encrypt function and a decrypt function) to produce an encrypted message from a "plaintext" message and a "plaintext" message from an encrypted message.The program should use a menu such as:1. Encrypt2. Decrypt3. ExitThe menu should be displayed in a loop until the user chooses to exit. When the user chooses the Encrypt option, your program should prompt the user to input a "plaintext" string. Then the program should display what the encrypted text would be.When the user chooses the Decrypt option, your program should prompt the user for an encrypted message and then display the "plaintext" version of that message to the user.For this program each message should be a single word and your cipher should use a shift of 3.Any message entered by the user should be capitalized using a user defined function that will take a string in by reference and use the toupper() function from to capitalize each letter of the string.
Computers and Technology
1 answer:
Len [333]3 years ago
8 0

Answer:

#include <iostream>

#include <stdio.h>

#include <ctype.h>

using namespace std;

string

encrypt (string text, int s)

{  string resultingString = "";

 for (int i = 0; i < text.length (); i++)

   {      if (!isspace (text[i]))

{

  if (isupper (text[i]))

    resultingString += char (int (text[i] + s - 65) % 26 + 65);

  else

  resultingString += char (int (text[i] + s - 97) % 26 + 97);

}

     else

{

  resultingString += " ";

}

  }

 return resultingString;

}

string

decrypt (string text, int s)

{

 string resultingString = "";

 for (int i = 0; i < text.length (); i++)

   {

     if (!isspace (text[i]))

{

  if (isupper (text[i]))

    resultingString += char (int (text[i] + s - 65) % 26 + 65);

  else

  resultingString += char (int (text[i] + s - 97) % 26 + 97);

}

     else

{

  resultingString += " ";

}

   }

 return resultingString;

}

string upper(string str){

   for (int i=0;i<str.length();i++){

       str[i]=toupper(str[i]);

   }

   return str;

}

int

main ()

{

 string text = "This is test text string";

 

 int s = 3;

 string cipherText = "";

 string decipherText = "";

int menu=-1;

while (menu!=3){

   cout<<"1. Encrypt"<<endl;

   cout<<"2. Decrypt"<<endl;

   cout<<"3. Exit"<<endl;

   cin >>menu;

   cin.ignore();

   if(menu==1){

       cout<<"Enter Plain string "<<endl;

       getline(cin,text);

       text=upper(text);

         cipherText = encrypt (text, s);

           cout << "cipher text: " << cipherText << endl;

   }

   else if(menu==2){

       cout<<"Enter Encrypted string "<<endl;

       getline(cin,cipherText);

               cipherText=upper(cipherText);

         decipherText = decrypt (cipherText, 26 - s);

 cout << "decipher text: " << decipherText << endl;

   }

   else {

       cout<<"Not valid"<<endl;

   }

}

 return 0;

}

Explanation:

Display menu with options 1 encrypt, 2 decrypt, 3 exit. Write a function to translate string to upper case. Iterate through string and for each index use toupper function to translate alphabet to upper case and store it back to current index of string.On exiting from loop return string. Pass upper case string to encrypt function.

In encrypt function pass string by reference and shift value. Create an empty string resultingString. Iterate through string for each character check if its space, if its a space add it to resulting string otherwise using ascii values convert char to its ascii add shift value and subtract 65 (staring ascii value for capital alphabet) take modules with 26 for new character and than add 65 to get alphabet.Now add this alphabet to resulting string. Upon loop completion return resultingString.

For decryption use same function as encryption. We are using cyclic property to decrypt using same function therefor subtract shift from 26 and pass resulting shift value to decrypt function.

You might be interested in
Match the items with their respective descriptions. organizes files make files easily searchable keeps track of file creation an
klemol [59]

Answer:

I'm not sure but I think its ,accessible file system are all on arrow right

4 0
3 years ago
Jenny needs to record the names of 30 students, write down the subjects they studied, and note grades in each subject after the
nevsk [136]
Mid semester and end semester. hope i helped
8 0
4 years ago
Read 2 more answers
15. You read a news article that's politically biased and not well organized. It's
kati45 [8]

You read a news article that's politically biased and not well organized. It's likely; A: A fake news

<h3>Understanding how to report a story</h3>

Let us look at each of the options given;

A: A fake news: This is a news that lacks credibility based on lack of proper research or evidence.

B: An indirect Citation; An indirect citation is when the ideas of one author are published in another author's text but then you have not read or accessed the original author's work.

C: A reliable source; This is a source that provides a thorough, well-reasoned theory, argument, discussion that is based on strong evidence.

D: A direct Citation; A direct citation is when you directly quote the exact words of an author or speaker.

Read more about reporting of a Story at; brainly.com/question/10111803

3 0
2 years ago
Arrange the types of movies in terms of the amount of content they can hold
posledela

Answer:

Well here is what I got...

Explanation:

Action

Crime

Fantasy

Horror

Romance

Science Fiction

Slice of Life

Sports

Thriller

War

Western

8 0
3 years ago
Convert ⅖ pie radian to degree​
aniked [119]

Answer:

Convert to a decimal.

22.9183118°

Explanation:

7 0
3 years ago
Other questions:
  • PLEASE HELP!!!!!!!!!!!
    11·2 answers
  • Assume that the population of Mexico is 128 million and that the population increases 1.01 percent annually. Assume that the pop
    7·1 answer
  • Makes it possible to distribute both power and data using ethernet cabling. select one:
    12·1 answer
  • What is not soured of income
    6·1 answer
  • We want to make a row of bricks that is goal inches long. We have a number of small bricks (1 inch each) and big bricks (5 inche
    5·1 answer
  • While saving her word-processed academic documents, Ashley includes the subject, title, and the author's name in the properties.
    7·1 answer
  • PLEASE AWNSER 50 POINTS PLUS BRAINLEST ILL FAIL MY GRADE IF I DONT AWNSER IN A HOUR!
    15·1 answer
  • The word “Intrapersonal”means----------------------.Within the personSelf talkExtrovertOutgoing person
    10·2 answers
  • g Define several forms of metadata that can be useful to an investigation. How are valuable to an investigator
    10·1 answer
  • WILL GIVE BRAINLEST!!!!!!!! 10 POINTS!!!!
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!