Question

In: Computer Science

Write a program in c++ that can perform encryption/decryption. In the following let the alphabet A...

Write a program in c++ that can perform encryption/decryption. In the following let the alphabet A be A={A, a, B, b, . . ., “ ”, “.”,“’ ”}. The encoding is A→0, a→1, B→2, b→4, . . ., Z→50, z→51, “ ”→52, “.”→53 and “’”→54.

Solutions

Expert Solution

For this code, we take a string text and ask the user to enter the plain text to encrypt. Then we take separate conditions for capital, small, and special characters and reduce them to the corresponding numbers and generate the cipher.

For decryption we ask the user for length of the code and the code itself. then we just use the separate conditions and reverse the formulas to get the plain text out of the code.

CODE:

/******************************************************************************

Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <cstring>

using namespace std;

int main()
{
string text;
int code[100];
int cypher[100];
cout<<"Enter plain text to be encrypted: ";
getline(cin, text);
cout<<"Encrypted text: ";
for (int i=0; i<text.length(); i++)
{
if(text[i]>=65 && text[i]<=90)
{
cypher[i] = (text[i]%65)*2;
}
else if(text[i]>=97 && text[i]<=122)
{
cypher[i] = ((text[i]%97)*2)+1;
}

if(text[i] == 32)
{
cypher[i] = 52;
}

if(text[i] == 46)
{
cypher[i] = 53;
}

if(text[i] == 39)
{
cypher[i] = 54;
}

cout<<cypher[i]<<" ";
}
  
int len;
cout<<"\nEnter the length of the cypher to decrypt: ";
cin>>len;
cout<<"Now enter the cypher: ";
for(int i=0; i<len; i++)
cin>>code[i];
cout<<"Decrypted text is: ";
for(int i=0; i<len; i++)
{
if(code[i]%2 == 0 && code[i] < 52)
text[i] = (code[i]/2) + 65;
  
if(code[i]%2 !=0 && code[i] <52)
text[i] = ((code[i]-1)/2) + 97;

if(code[i]==52)
text[i] = 32;
  
if(code[i]==53)
text[i] = 46;
  
if(code[i]==54)
text[i] = 39;
  
cout<<text[i];
}


return 0;
}

OUTPUT:


Related Solutions

Write a program in java that can perform encryption/decryption. In the following let the alphabet A...
Write a program in java that can perform encryption/decryption. In the following let the alphabet A be A={A, a, B, b, . . ., “ ”, “.”,“’ ”}. The encoding is A→0, a→1, B→2, b→4, . . ., Z→50, z→51, “ ”→52, “.”→53 and “’”→54.
write a C program which performs encryption and decryption of a message
write a C program which performs encryption and decryption of a message
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 :)
Your task is to write a C program which performs encryption and decryption of a message...
Your task is to write a C program which performs encryption and decryption of a message using the substitution cipher algorithm. Write a C program which performs encryption and decryption using the substitution cipher algorithm. Your program must be fully automated (ie: it does not take any interactive user input) and either encrypt or decrypt depending on the files which exist in the program’s directory. If message.txt exists your program should read that file, encrypt the contents, and write the...
write a C++ program that : 1. Perform a rot13 substitution 2. Perform a caesar encryption...
write a C++ program that : 1. Perform a rot13 substitution 2. Perform a caesar encryption given a dictionary 3. Perform a caesar decryption given a dictionary 4. Create a random caesar cipher dictionary If user prints: -r : Perform rot13 substitution -g : generate a random caesar cipher dictionary. -e: Encrypt using the caesar cipher -d : Decrypt using the caesar cipher The format for the caesar cipher dictionary is a file with 26 pairs of letters, one per...
My question below Write a complete program that performs encryption/decryption of a text file. Encryption means...
My question below Write a complete program that performs encryption/decryption of a text file. Encryption means you need to scramble the words of a file to become secure. Decryption means you need to apply some rules to an encrypted file in order to find the original file with its original content. An example of encryption is to replace each letter in a file with its consecutive letter in the alphabet. Therefore, ‘a’ is replaced by ‘b’, ‘b’ is replaced by...
USE C++: Encryption and Decryption are two cryptographic techniques. Encryption is used to transform text to...
USE C++: Encryption and Decryption are two cryptographic techniques. Encryption is used to transform text to meaningless characters, and decryption is used to transform meaningless characters into meaningful text. The algorithm that does the encryption is called a cipher. A simple encryption algorithm is Caesar cipher, which works as follows: replace each clear text letter with a letter chosen to be n places later in the alphabet. The number of places, n, is called the cipher key. For example, if...
Please perform encryption and decryption given the following values of an RSA public key cryptosystem; p=17,...
Please perform encryption and decryption given the following values of an RSA public key cryptosystem; p=17, q=31, e=7 and M=2
Alice is sending message “HIDE” to Bob. Perform encryption and decryption using RSA algorithm, with the...
Alice is sending message “HIDE” to Bob. Perform encryption and decryption using RSA algorithm, with the following information: parameters p=11,q=5, e=7 Present all the information that you will need to encrypt and decrypt only the first letter from text
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:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT