通过修改文件字符对单一文件进行简单加密

#include <iostream>
using namespace std;

void jiaMi(const char* filename)
{
	FILE* fp = fopen(filename, "r+");
	char c = fgetc(fp);
    fseek(fp, 0, SEEK_SET);
	c = (int)c + 1;
	fwrite(&c, 1, 1, fp);
	fclose(fp);
}

void jieMi(const char* filename)
{
	FILE* fp = fopen(filename, "r+");  //以读写方式打开
	char c = fgetc(fp);
	fseek(fp, 0, SEEK_SET);  //由于fgetc后,指针会移位,因此必须重置指针
	c = (int)c - 1;
	fwrite(&c, 1, 1, fp);
	fclose(fp);
}

void main()
{	
	const char* filename = "C:/Users/大蚂蚁一号/Desktop/1.png";
    jiaMi(filename);
    jieMi(filename);
}

你可能感兴趣的:(通过修改文件字符对单一文件进行简单加密)