复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41#include <iostream> #include <fstream> using namespace std; int main(){ ifstream iFile("MySong.txt"); //get the length of the file iFile.seekg(0,ios::end); int nFileLen = iFile.tellg(); iFile.seekg(0,ios::beg); //allocate memory char* str = new char[nFileLen+1]; //read data as block iFile.read(str,nFileLen);//读取nFileLen个字节的数据并存储到str变量 iFile.close(); str[nFileLen]=0; int nCaesar = 3;//假设Caesar移位为3 int n=0;//记录回车数目 for(int i=0;i< nFileLen;i++){ //不做任何处理,直接输出字符,看是否出现rn printf("%c",str[i]); //开始对字母进行加密,如果位移后大于'z'或'Z',则减去26 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; } } } ofstream oFile("mySong2.txt"); oFile.write(str,nFileLen); oFile.close(); delete[] str; return 0; }
最后
以上就是辛勤汽车最近收集整理的关于c++ 凯撒加密的全部内容,更多相关c++内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复