C ++中的Polybius Square密码
在这个问题中,我们得到了一个字符串,我们必须使用PolybiusSquareCipher来找到其整数加密。
波利比乌斯广场密码
该表用于将字母转换为数字。用于英语加密的表格是5X5表格,即包含25个单元格,用于英语词典的26个字母。字母i和j放在一个单元格中。
下表显示了Polybius方形密码-
表格的字母可以是随机的。而且,可以基于语言的字母数来改变表的大小。
让我们举个例子来了解这个问题,
输入-你好
输出-2315313134
为了解决这个问题,我们将创建一个程序以获取每对数字,然后检查相应的字母。
示例
程序来显示我们的解决方案的图示-
#include <cmath>
#include <iostream>
using namespace std;
void LetterToNumber(string str) {
int R, C;
for (int i = 0; str[i]; i++) {
R = ceil((str[i] - 'a') / 5) + 1;
C = ((str[i] - 'a') % 5) + 1;
if (str[i] == 'k') {
R = R - 1;
C = 5 - C + 1;
}
else if (str[i] >= 'j') {
if (C == 1) {
C = 6;
R = R - 1;
}
C = C - 1;
}
cout<<R<<C;
}
cout << endl;
}
int main() {
string str = "nhooo";
cout<<"The numeric encryption of string '"<<str<<"' is : ";
LetterToNumber(str);
return 0;
}输出结果
The numeric encryption of string 'nhooo' is: 4445443442241131433534243344