In: Computer Science
Choose one of the following cryptography techniques and implement it using any programming language you prefer. Your program should provide the user with two options Encryption and Decryption, with a simple UI to get the input from the user, and view the result. You can use any restriction you need for the user input but you need to clarify that and validate the user input base on your restriction.
● Feistel
● Keyword columnar
● Any cryptosystem of your choice (needs to be approved by the instructor)
Notes:
In below code I have used Caesar cipher as a cryptography techniques for encryption and decryption of plain text and C++ language to implement the code.
Caesar_cipher.cpp
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main() {
// User input to Encrypt text
cout<<"Enter your Plain text:";
char text[50];
cin.getline(text,50);
int i, j,n,choice,key;
// Key or shift value which used to encrypt text
cout << "Enter key: ";
cin >> key;
n = strlen(text);
while(1){
//user menu
cout<<"\n1.Encryption\n2.Decryption\n3.Exit\n";
cout<<"Enter your choice:";
cin>>choice;
if (choice==1){
char word;
for(int i = 0; text[i] != '\0'; ++i) {
word = text[i];
// encryption for lowercase letters
if (word >= 'a' && word <= 'z'){
word = word + key;
if (word > 'z') {
word = word - 'z' + 'a' - 1;
}
text[i] = word;
}
// encryption for uppercase letters
else if (word >= 'A' && word <= 'Z'){
word = word + key;
if (word > 'Z'){
word = word - 'Z' + 'A' - 1;
}
text[i] = word;
}
}
// Encrypted text or result
cout<<"\nEncrypted text:"<<text<<endl;
}
else if (choice == 2) {
char word;
for(int i = 0; text[i] != '\0'; ++i) {
word = text[i];
//decryption for lowercase letters
if(word >= 'a' && word <= 'z') {
word = word - key;
if(word < 'a'){
word = word + 'z' - 'a' + 1;
}
text[i] = word;
}
//decryption for uppercase letters
else if(word >= 'A' && word <= 'Z') {
word = word - key;
if(word < 'A') {
word = word + 'Z' - 'A' + 1;
}
text[i] = word;
}
}
// Decrypted text or result
cout <<"\nDecrypted text:"<<text<<endl;
}
// For exiting the menu on operation complete
else if (choice == 3) {
exit(0);}
}
}
Output :- You can see the below screenshot for output of above code.
Please hit that like or thumbs-up button, It really motivates me(It takes only 1-2 seconds,I hope you will do that?)>3
Thank you!!