Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // sqfcryptor.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <string>
- #include <iostream>
- #include <fstream>
- #define WIN32_LEAN_AND_MEAN
- #include <Windows.h>
- std::string Encrypt(const std::string &strPlain, const std::string &strPass)
- {
- std::string strCrypt;
- strCrypt.reserve(strPlain.size());
- for(size_t i = 0; i < strPlain.size(); i++)
- {
- unsigned char u = strPlain[i];//unencrypted
- unsigned char p;//password
- if(i == 0)
- {
- p = strPass[0];
- }
- else
- {
- p = strPass[(strPass[(i-1)%strPass.size()]*i)%strPass.size()];
- }
- unsigned char e = u ^ p;//encrypted
- if(i > 0)
- {
- e ^= strPlain[i-1];
- }
- strCrypt += e;
- }
- return strCrypt;
- }
- std::string StringReplace(std::string str, const std::string &strReplace, const std::string &strWith, unsigned int count = 0)
- {
- size_t pos = str.find(strReplace);
- for(unsigned int i = 0; pos != std::string::npos && (i < count || count == 0); i++)
- {
- str.replace(pos, strReplace.size(), strWith);
- pos = str.find(strReplace);
- }
- return str;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- std::string strPass;
- std::cout << "Enter encryption password:";
- std::getline(std::cin, strPass);
- WIN32_FIND_DATAA ffd;
- HANDLE hFileSearch = FindFirstFileA("*.sqf", &ffd);
- bool bFoundFile = true;
- while(hFileSearch != NULL && bFoundFile)
- {
- if(std::string(ffd.cFileName).find("_enc.sqf") == std::string::npos)
- {
- std::cout << "Found sqf: " << ffd.cFileName << std::endl;
- std::ifstream fInput;
- fInput.open(ffd.cFileName, std::ios_base::in | std::ios_base::binary);
- fInput.seekg(0, std::ifstream::end);
- std::string strFile;
- strFile.reserve(fInput.tellg());
- fInput.seekg(0, std::ifstream::beg);
- strFile.assign(std::istreambuf_iterator<char>(fInput), std::istreambuf_iterator<char>());
- fInput.close();
- strFile = Encrypt(strFile, strPass);
- std::ofstream fOutput;
- fOutput.open(StringReplace(ffd.cFileName, ".sqf", "_enc.sqf", 1), std::ios_base::out | std::ios_base::binary
- | std::ios_base::trunc);
- fOutput << "[";
- for(size_t i = 0; i < strFile.size(); i++)
- {
- fOutput << unsigned int(strFile[i]);
- if(i != strFile.size()-1)
- {
- fOutput << ",";
- }
- }
- fOutput << "]";
- fOutput.close();
- }
- bFoundFile = FindNextFileA(hFileSearch, &ffd);
- };
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement