算法一 : 凯撒加密 (只能对英文的txt) 将每个字符的ASCII码相对于设置的偏移量偏移
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream iFile("D:\\测试1.txt"); //建立输入文件流对象
iFile.seekg(0, ios::end);
int nFileLen = iFile.tellg();
iFile.seekg(0, ios::beg);
char *str = new char[nFileLen + 1];
iFile.read(str, nFileLen);
iFile.close();
str[nFileLen] = 0;
int nCaesar = 5; //设置偏移量
int n = 0; //记录回车数目
for (int i = 0; i < nFileLen; i++)
{
if ((str[i] >= 'a') && (str[i] <= 'z'))
{
str[i] += nCaesar;
if (str[i] > 'z')
str[i] -= 26;
}
else if ((str[i] >= 'A') && (str[i] <= 'Z'))
{
str[i] += nCaesar;
if (str[i] > 'Z')
str[i] -= 26;
}
else if (str[i] == '\n')
n

本文介绍了凯撒加密算法,这是一种简单的替换加密技术,通过将字母表上的字母按固定偏移量移动进行加密。虽然易被破解,但在现代密码学中仍作为基础步骤存在。文章解释了代码中减去26的原因,以确保加密后的字符仍为字母,并讨论了处理回车字符在文件加密中的重要性。
最低0.47元/天 解锁文章
3464

被折叠的 条评论
为什么被折叠?



