c - 从 .txt 字符中减去添加的数字不会反向加密?
问题描述
当加密文本文件,然后使用“字节密钥”运行算法以撤消加密时,它只是更改了混乱的文本,实际上并没有反转任何内容。有什么我缺少的概念吗?
void encrypt(char filePath[],int key) {
FILE * file;
char byte;
file = fopen(filePath,"r+");
while( (byte = fgetc(file)) != EOF) {
fputc(byte+key,file);
}
fclose(file);
}
解决方案
这是我的新加密功能的外观
void encrypt(char filePath[],int key) {
FILE * fileR;
FILE * fileW;
char dest[500],src[4];
int byte;
fileR = fopen(filePath,"r");
//Combines filePath with ext for unique filename
strcpy(dest,filePath);
strcpy(src,ext);
fileW = fopen(strcat(dest,src),"w");
while( (byte = fgetc(fileR)) != EOF) {
fputc(byte+key,fileW);
}
fclose(fileR);
fclose(fileW);
}
它现在按预期工作。
推荐阅读
- java - COBOL viewcall响应字符串到java bean的解决方案
- sql - 用户在网站上访问且从未返回的最后一页
- python - 用于在python中匹配德语字符的正则表达式
- android - ConstraintLayout - 对齐两个视图以垂直居中另一个视图
- java - 如何解决我的项目中的 Thread-Exception 错误
- xamarin.forms - BindingMode=TwoWay 在代码隐藏中
- python - Time Travel Debugging in Python - what tools are suggested to use?
- ios - 组合 combineLatest 不等待上一个操作触发
- c# - 如何在 SQL 中批量从大表中选择记录
- swift - NSDocumentController.openDocument 不允许选择自定义文件类型