Skip to content

Instantly share code, notes, and snippets.

@ctkqiang
Created August 3, 2020 00:37
Show Gist options
  • Select an option

  • Save ctkqiang/0faa43ea91c953d3e84b9700030e340d to your computer and use it in GitHub Desktop.

Select an option

Save ctkqiang/0faa43ea91c953d3e84b9700030e340d to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main()
{
int i, x;
char str[100];
cout << "Please enter a String: \t";
cin >> str;
cout << "\n Please Choose The Following Options: \n";
cout << "[1] ENCRYPT STRING. \n";
cout << "[2] DECRYPT STRING. \n";
cin >> x;
switch (x)
{
case 1:
for (i = 0; (i < 100 && str[i] != '\0'); i++)
{
str[i] = str[i] + 2; //the key for encryption is 3 that is added to ASCII value
}
cout << "\nEncrypted string: " << str << endl;
break;
case 2:
for (i = 0; (i < 100 && str[i] != '\0'); i++)
{
str[i] = str[i] - 2; //the key for encryption is 3 that is subtracted to ASCII value
}
cout << "\nDecrypted string: " << str << endl;
break;
default:
cout << "\nInvalid Input !!!\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment