admin管理员组文章数量:1565292
EncodeAndDecode.h
#pragma once
#include "afxdialogex.h"
class EncodeAndDecode
{
public:
EncodeAndDecode();
~EncodeAndDecode();
void EncodeFile();
void DecodeFile();
};
EncodeAndDecode.cpp
#include "stdafx.h"
#include "EncodeAndDecode.h"
#include "afxdialogex.h"
EncodeAndDecode::EncodeAndDecode()
{
}
EncodeAndDecode::~EncodeAndDecode()
{
}
void EncodeAndDecode::EncodeFile()
{
//读取配置文件
CString fPath("./data.txt");
CFile openFile;
bool bFile = openFile.Open(fPath, CFile::modeRead);
//同根目录下判断是否打开
if (!bFile)
{
MessageBox(NULL,_T("系统文件丢失请联系管理员"), _T("错误") ,MB_ICONINFORMATION);
exit(0);
}
DWORD openSize = (DWORD)openFile.GetLength();
char* buf = new char[openSize + 1];
memset(buf, 0, sizeof(char) * (openSize + 1));
openFile.Read(buf, openSize);
openFile.Close();
//加密算法
for (unsigned int i = 0; i < openSize; i++)
{
buf[i] = 255 - buf[i];
}
//写入加密文件
CString wPath("./moon.xie");
CFile writeFile;
writeFile.Open(wPath, CFile::modeWrite | CFile::modeCreate);
writeFile.Write(buf, openSize);
writeFile.Close();
//MessageBox(NULL, _T("已加密"), _T("成功"), MB_ICONINFORMATION);
}
void EncodeAndDecode::DecodeFile()
{
//读取加密文件
CString fPath("./moon.xie");
CFile openFile;
bool bFile = openFile.Open(fPath, CFile::modeRead);
//同根目录下判断是否打开
if (!bFile)
{
MessageBox(NULL,_T("系统文件丢失请联系管理员"), _T("错误"), MB_ICONINFORMATION);
exit(0);
}
DWORD openSize = (DWORD)openFile.GetLength();
char* buf = new char[openSize + 1];
memset(buf, 0, sizeof(char) * (openSize + 1));
openFile.Read(buf, openSize);
openFile.Close();
//解密算法
for (unsigned int i = 0; i < openSize; i++)
{
buf[i] = 255 - buf[i];
}
//写入解密文件
CString wPath("./data.txt");
CFile writeFile;
writeFile.Open(wPath, CFile::modeWrite | CFile::modeCreate);
writeFile.Write(buf, openSize);
writeFile.Close();
//MessageBox(NULL,_T("已解密"), _T("成功"), MB_ICONINFORMATION);
}
版权声明:本文标题:MFC对TXT文档进行加密解密 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1726165130a1058143.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论