#include "EncryptFile.h" #include "File.h" #include "FileSystem.h" #define ENCRYPT_LEN (100) NAMESPACE_MAS_BEGIN TZ_INT EncryptFile::encryptXor(const std::string & inputPath) { tzc::ExecPath path(inputPath); if (!path.IsExist()) { TZLogInfo("file \"%s\" not found!!!\n", inputPath.c_str()); return MEC_NULL_OBJ; } TZ_INT buffLen = path.GetFileSize() > ENCRYPT_LEN ? ENCRYPT_LEN : path.GetFileSize(); tzc::PrimeFile f(inputPath); f.Open(tzc::File::FileOpenMode::OpenModeRead | tzc::File::FileOpenMode::OpenModeWrite | tzc::File::FileOpenMode::OpenModeBinary | tzc::File::FileOpenMode::OpenModeSync); TZ_BYTE pData[buffLen]; f.Read(pData, buffLen); for (int i = 0; i < buffLen / 2; ++i) { pData[i] ^= (i & 1) ? 'c' : 'y'; pData[buffLen - 1 - i] ^= (i & 1) ? 'c' : 'y'; std::swap(pData[i], pData[buffLen - 1 - i]); } f.Seek(0, tzc::File::FileSeekPos::SeekPosSet); f.Write(pData, buffLen); f.Close(); return MEC_OK; } TZ_INT EncryptFile::decryptXor(const std::string & inputPath) { return EncryptFile::encryptXor(inputPath); } NAMESPACE_MAS_END