Question

In: Computer Science

use C++ You will implement the following encryption and decryption functions/programs for the Caesar cipher. Provide...

use C++

You will implement the following encryption and decryption functions/programs for the Caesar cipher. Provide the following inputs and outputs for each function/program:

EncryptCaesar

  • Two inputs:

    • A string of the plaintext to encrypt

    • A key (a number)

      ▪ For the Caesar cipher: This will indicate how many characters to shift (e.g. for a key=3, A=>D, B=>E, ..., X=>A, Y=>B, Z=>C). Note that the shift is circular.

  • One output:
    ◦ A string of the ciphertext or codeword

    DecryptCaesar

  • Two inputs:
    ◦ A string of the ciphertext to decrypt ◦ The key (a number)

  • One output:
    ◦ A string of the plaintext

    Obviously, for this assignment to be successful, the decryption function/program must decrypt the original message which was encrypted by the encryption function/program. Or, for a plaintext P and an encryption function E() and a decryption function D(), P = D( E(P, Key), Key)

Solutions

Expert Solution

  • Code Snippet Without Text-

  • Code With Text-

//required libraries are included
#include <iostream>
#include <algorithm>
#include <string.h>
#include <map>

using namespace std;

//start of main function
int main()
{   
//declarations and initialisations
string plain_text,cipher_text;
int key_p,key_c,size_plain_text, size_cipher_text;
int value1,value2,j,i;
char value_char;
  
//reference list of characters
char my_list[]={'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'};
  
   cout<<"Enter a Plain String to Encrypt-"<<endl;
   cin>>plain_text;
   cout<<"Enter the Key for Encryption-"<<endl;
   cin>>key_p;
  
   cout<<"Enter a Cipher String to Decrypt-"<<endl;
   cin>>cipher_text;
   cout<<"Enter the Key for Decryption-"<<endl;
   cin>>key_c;
  
   //size of texts are found here
   size_plain_text=plain_text.size();
   size_cipher_text=cipher_text.size();
  
   char encrypted_text[size_plain_text],decrypted_text[size_cipher_text];
  
   //Encryption Loop
   for(i=0;i<size_plain_text;i++)
   {
   //Caesar Encryption Functional Statements
   value1=plain_text[i];
   value1=value1-65;
  
   value1=value1+key_p;
   value1=value1%26;
  
  
   encrypted_text[i]=my_list[value1];
  
   }
  
   //Decryption Loop
   for(j=0;j<size_cipher_text;j++)
   {
  
   //Caesar Decryption Functional Statements
   value2=cipher_text[j];
   value2=value2-65;
  
   value2=value2-key_p;
   if(value2<0)
   {
   value2=26+value2;
   }
  
   decrypted_text[j]=my_list[value2];
  
   }
  
   cout<<"Encrypted Text is: "<<encrypted_text<<endl;
   cout<<"Decrypted Text is: "<<decrypted_text<<endl;
  
   return 0;
}

  • Input/Output Snippet-

​​​​​​​


Related Solutions

In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The program should be able to handle different keys by deciding the key at run time. Thank you :)
The mathematical expression of the encryption and decryption process of a Caesar cipher algorithm is expressed...
The mathematical expression of the encryption and decryption process of a Caesar cipher algorithm is expressed respectively as: c=Ep, k=p+k%26                                                                                                                         (1) p=Dc,k=c-k%26                                                                                                                         (2) Please do the following: Write at least two paragraphs to explain the principle of operation of the algorithm. For a full credit, your explanation must show the architectural diagram of the encryption and decryption process. Write a program to implement the Caesar algorithm Code must have two functions; encryption and decryption Test your codes with p as...
In cryptography, Caesar cipher is one of the simplest encryption techniques. The key idea of this...
In cryptography, Caesar cipher is one of the simplest encryption techniques. The key idea of this method is to replace each plaintext letter with one fixed number of places down the alphabet. Below is an example with a shift of three: Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz Cipher: DEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABC To cipher a string, ‘A’ is replaced by ‘D’, ‘B’ is substituted by ‘E’, and so on. To decode a string, ‘A’ is replaced by ‘x’, etc. By using python with vs code: Write a...
Problem 2: Caesar Cipher Decryption] Write a python method that takes two parameters: A parameter of...
Problem 2: Caesar Cipher Decryption] Write a python method that takes two parameters: A parameter of type str and a parameter of type int. The first parameter is the plaintext message, and the second parameter is the encryption key. The method strictly does the following tasks: a. Reverse the operations performed by the encryption method to obtain the plaintext message. The method’s header is as follows: def casesardecryption(s, key):
Caesar Cipher Encryption] Write a method that takes two parameters: A parameter of type str and...
Caesar Cipher Encryption] Write a method that takes two parameters: A parameter of type str and a parameter of type int. The first parameter is the plaintext message, and the second parameter is the encryption key. The method strictly does the following tasks: a. Convert the string into a list (let us refer to it as lista). An element in the generated list is the position of the corresponding letter in the parameter string in the English alphabet. Example: ‘C’...
In the caeser cipher encryption and decryption program below, what do the two lines if(ch >...
In the caeser cipher encryption and decryption program below, what do the two lines if(ch > 'z'){ ch = ch - 'z' + 'a' - 1; } if(ch < 'a'){ ch = ch + 'z' - 'a' + 1; } mean??? I understand that it has something to do with ASCII characters and makes sure that if the encryption/decryption character is more than "z", then it would loop back to "a" instead of outputting a charcter like "{" . I...
The given plaintext is “Feistel cipher structure uses the same algorithm for both encryption and decryption”....
The given plaintext is “Feistel cipher structure uses the same algorithm for both encryption and decryption”. Write Java code to implement Shift cipher (Encryption and Decryption) and test your code on given plaintext. Your code must meet following conditions. 1. User must enter the value of key from command prompt and print it at command prompt. 2. Print the cipher text and the plaintext at the command prompt after encryption and decryption. 3. Test your algorithm for 5 different key...
COP2271 MATLAB HW9 Homework: Modified Vigenere Cipher Implement a decryption cipher to decode messages using a...
COP2271 MATLAB HW9 Homework: Modified Vigenere Cipher Implement a decryption cipher to decode messages using a secret key. You are required to submit the solution and screenshots for this question. Key programming concepts: if statements, loops, strings Approximate lines of code: 27 (does not include comments or white space) Commands you can’t use: None... Program Inputs • Enter message to decrypt: • Enter secret key: – The user will always enter text for all prompts, no error checking needed. The...
C++ The Caesar cipher is one of the earliest known and simplest ciphers. It is a...
C++ The Caesar cipher is one of the earliest known and simplest ciphers. It is a type of substitution cipher in which each letter in the plaintext is 'shifted' a certain number of places down the alphabet. 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 U V W X Y Z A B C D E F G H I J K...
In this module you learned how to implement recursive functions in your C++ programs. For this...
In this module you learned how to implement recursive functions in your C++ programs. For this assignment, you will create a program that tests a string to see if it is a palindrome. A palindrome is a string such as “madam”, “radar”, “dad”, and “I”, that reads the same forwards and backwards. The empty string is regarded as a palindrome. Write a recursive function: bool isPalindrome(string str, int lower, int upper) that returns true if and only if the part...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT