Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Vig {
- public:
- string k;
- Vig(string k) {
- for (int i = 0; i < k.size(); ++i) {
- if (k[i] >= 'A' && k[i] <= 'Z')
- this->k += k[i];
- else if (k[i] >= 'a' && k[i] <= 'z')
- this->k += k[i] + 'A' - 'a';
- }
- }
- string encryption(string t) {
- string output;
- for (int i = 0, j = 0; i < t.length(); ++i) {
- char c = t[i];
- if (c >= 'a' && c <= 'z')
- c += 'A' - 'a';
- else if (c < 'A' || c > 'Z')
- continue;
- output += (c + k[j] - 2 * 'A') % 26 + 'A';
- j = (j + 1) % k.length();
- }
- return output;
- }
- string decryption(string t) {
- string output;
- for (int i = 0, j = 0; i < t.length(); ++i) {
- char c = t[i];
- if (c >= 'a' && c <= 'z')
- c += 'A' - 'a';
- else if (c < 'A' || c > 'Z')
- continue;
- output += (c - k[j] + 26) % 26 + 'A';
- j = (j + 1) % k.length();
- }
- return output;
- }
- };
- int main() {
- Vig v("WELCOME");
- string ori ="Laganapetica";
- string encrypt = v.encryption(ori);
- string decrypt = v.decryption(encrypt);
- cout << "Original Message: "<<ori<< endl;
- cout << "Encrypted Message: " << encrypt << endl;
- cout << "Decrypted Message: " << decrypt << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement