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...
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...
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
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 prompt is using Python:  Write a 3 rail transposition encryption algorithm, and a corresponding decryption algorithm....
The prompt is using Python:  Write a 3 rail transposition encryption algorithm, and a corresponding decryption algorithm. Implement these two algorithms in their own function. Now write a testing function that demonstrates your algorithms work for all interesting cases!
Write a program in C to perform the following: Generates an array of 10 double random...
Write a program in C to perform the following: Generates an array of 10 double random values between 1.0 and 100.0 – assume these are prices for 10 items that a store sells Generates an array of 10 integer random values between 0 and 200 – assume that these are the number of items/units (first array) sold Generate another array called “itemSale” which would contain the total sale for each item. Calculate the total sale for this store and display...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT