Column
unknown
c_cpp
2 years ago
1.3 kB
7
Indexable
#include <iostream>
#include <cstring>
using namespace std;
int main(){
char matrix[10][10];
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 < 10; j++){
matrix[i][j] = 'x';
}
cout << 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(char c : key){
int col = c - '0' - 1;
if (col >= 0 && col < key.length()){
cipher += matrix[i][col];
}
}
}
cout << "After encryption: " << cipher;
return 0;
}
Editor is loading...
Leave a Comment