?? cryptfile.cpp
字號:
#include "stdafx.h"
#include "cryptfile.h"
BOOL CCryptFile::Open( LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError)
{
CFile raw;
// you'd like to test for modeRead, but since it is 0, that doesn't work
if ((nOpenFlags & (CFile::modeReadWrite|CFile::modeWrite))==0)
{
if (!raw.Open(lpszFileName,nOpenFlags,pError))
{
return FALSE;
}
unsigned n;
n=raw.GetLength();
unsigned char *p=(unsigned char *)malloc(n);
raw.Read(p,n); // read entire file
raw.Close();
// decrypt
for (unsigned i=0;i<n;i++)
p[i]^=0xFF;
Attach(p,n);
}
else
basefile=lpszFileName;
return TRUE;
}
void CCryptFile::Close( )
{
CFileException pError;
CFile raw;
// if saving, encrypt data and write to real file
if (!basefile.IsEmpty())
{
unsigned n=GetLength();
if (!raw.Open(basefile,CFile::modeWrite|CFile::modeCreate|CFile::shareExclusive,&pError))
throw &pError;
unsigned char *p=Detach();
// encrypt
for (unsigned i=0;i<n;i++)
p[i]^=0xFF;
raw.Write(p,n);
raw.Close();
free(p);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -