Column
unknown
c_cpp
2 years ago
1.3 kB
5
Indexable
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<vector<char>> matrix(10, vector<char>(10, 'x'));
int count=0, lastRow=0;
string str, cipher, key;
cout << "Input the normal text: ";
getline(cin, str);
cout << "Input the key: ";
getline(cin, key);
cout << endl << "Before encryption: " << str << endl;
for(int i=0; i<10; i++){
for(int j=0; j<key.length() && count<str.length(); j++){
if(str[count] != ' '){
matrix[i][j] = str[count];
count++;
lastRow=i;
}
else{
j--;
count++;
}
}
}
for(int i=0; i<=lastRow; i++){
for(int j=0; j<key.length(); j++){
cout<<matrix[i][j]<<" ";
}
cout << endl;
}
for(int i=0; i<=lastRow; i++){
for(int j=0; j<key.length(); j++){
cout<<matrix[i][j]<<" ";
}
cout << endl;
}
cout<<endl;
for (char c:key){
int col=c-'0'-1;
if (col>=0 && col<key.length()){
for (int i=0; i<=lastRow; i++){
cipher += matrix[i][col];
}
}
}
// int num = stoi(str);
cout<<"After encryption: "<<cipher;
}Editor is loading...
Leave a Comment