Poly
unknown
c_cpp
2 years ago
2.0 kB
4
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<<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]; } } // if(str[i-1] == ' '){ // if(str[i] == before[j]){ // cipher += after[j]; // } // else if (str[i] == ' ') { // cipher += ' '; // i++; // } // } // else if(str[i+1] == ' '){ // if(str[i] == before[j]){ // cipher += after[j+3]; // } // else if (str[i] == ' ') { // cipher += ' '; // i++; // } // } // else{ // if(str[i] == before[j]){ // cipher += after[j+6]; // } // else if (str[i] == ' ') { // cipher += ' '; // i++; // } // } } } cout<<"After encryption: "<<cipher; }
Editor is loading...
Leave a Comment