Poly

 avatar
unknown
c_cpp
2 years ago
1.2 kB
3
Indexable
#include<bits/stdc++.h>
using namespace std;

int main(){
    char before[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
            'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
            's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
    
    char after[] = { 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O',
            'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K',
            'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M' };

    string str, cipher;
    cout<<"Input the normal text: ";
    getline(cin, str);
    cout<<endl<<"Before encryption: "<<str<<endl;

    for(int i=0; i<26; i++){
        // size_t pos = str.find(str[i]);
        for(int j=0; j<str.length(); j++){
            if(before[i] == str[j]){
                if(str[j-1] == ' ' || j==0) cipher += after[i];
                else if(str[j+1] == ' ' || j==str.length()-1) cipher += after[i+6];
                else if(str[j] == ' '){
                    cipher += ' ';
                    j++;
                }
                else{
                    cipher += after[i+3];
                }
            }
        }
    }
    cout<<"After encryption: "<<cipher;

}
Editor is loading...
Leave a Comment