c++ - 使用 EOT 的 Playfair 算法解密问题
问题描述
我正在尝试使用 16x16 矩阵实现 playfair 算法。目前,如果没有一对字符可以将自己加密为 ascii 表中的 EOT 字符,那么我在加密和解密文件时没有问题。
下面是我用于读取 2 个字符的当前代码:
ifstream input_file(file);
ofstream output_file("out_d.txt");
if (input_file.is_open()) {
char A, B;
//get total number of characters in the file
input_file.seekg(0, input_file.end);
int length = input_file.tellg();
input_file.seekg(0, input_file.beg);
//while (input_file.get(A)) {
for (int cnt = 0; cnt < length / 2; cnt++) {
input_file.get(A);
//if there are 2 same characters in the pair
if (A == input_file.peek()) {
B = char(0);
}
//if there is a EOT charater ignore it and skip 1 character
else if (input_file.peek() == char(3) && cnt != (length / 2) - 1) {
input_file.ignore();
B = char(3);
}
else {
input_file.get(B);
}
//down here is the decryption section
...
}
}
我要问的是是否可以跳过或更改文件迭代器的位置,所以即使有多个 EOT 字符,我也可以解密整个文件。
解决方案
推荐阅读
- javascript - express body-parser 在 req 对象中返回空正文
- javascript - 获取嵌套 HTML 中的 HTML 元素
- javascript - ShieldUI Grids:如何获取触发双击的行
- animation - AppBar 图标在页面间转换
- algorithm - 如何将条形码解码为 ISBN?
- python - 如何在python中命名和创建一个类的多个实例?
- java - 如何打印以下图案
- javascript - Pentaho CDF 错误:对象类型 *Component* 无法映射到有效类
- c# - QueryString 的问题:从客户端 (&) 检测到潜在危险的 Request.Path 值
- java - 我的注册没有发送到 firebase