CXOR/cxor.cpp

85 lines
1.9 KiB
C++
Raw Normal View History

2021-04-23 21:31:42 +02:00
#include <iostream>
#include <fstream>
#include <boost/program_options.hpp>
2021-04-26 21:29:58 +02:00
#include <string>
#include <vector>
namespace po = boost::program_options;
void parseargs(int argc, char* argv[])
{
2021-04-26 21:29:58 +02:00
bool bInputHex = false;
bool bOutputHex = false;
std::string sInputFile;
std::string sOutputFile;
po::options_description desc("Allowed options");
desc.add_options()
("help", "Print this message")
2021-04-26 21:29:58 +02:00
("input,i", po::value<std::string>(), "Specify an input file")
("ih", "Input data is in hex")
("output,o", "Specify an output file")
("oh", "Output data in hex")
;
po::positional_options_description p;
p.add("input", -1);
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help"))
{
std::cout << desc << std::endl;
}
if (vm.count("input"))
{
2021-04-26 21:29:58 +02:00
std::string file = vm["input"].as<std::string>();
std::string filecut = file.substr(1, file.length());
std::cout << filecut;
}
2021-04-26 21:29:58 +02:00
if (vm.count("ih"))
{
2021-04-26 21:29:58 +02:00
bool bInputHex = true;
}
2021-04-26 21:29:58 +02:00
if (vm.count("output"))
{
2021-04-26 21:29:58 +02:00
std::string file = vm["output"].as<std::string>();
std::string filecut = file.substr(1, file.length());
std::cout << filecut;
}
2021-04-26 21:29:58 +02:00
if (vm.count("oh"))
{
2021-04-26 21:29:58 +02:00
bool bOutputHex = true;
}
}
2021-04-23 21:31:42 +02:00
2021-04-26 21:29:58 +02:00
std::vector<char> xormessage(std::string sMessage, std::string sKey)
2021-04-23 21:31:42 +02:00
{
2021-04-26 21:29:58 +02:00
std::vector<char> cXORMessage;
int iKeyIndex = 0;
2021-04-26 21:29:58 +02:00
for (int iMessageIndex = 0; iMessageIndex < sMessage.length(); iMessageIndex++)
2021-04-23 21:31:42 +02:00
{
2021-04-26 21:29:58 +02:00
cXORMessage.push_back(sMessage[iMessageIndex] ^ sKey[iKeyIndex]);
iKeyIndex++;
if (iKeyIndex == sKey.length())
2021-04-23 21:31:42 +02:00
{
2021-04-26 21:29:58 +02:00
iKeyIndex = 0;
2021-04-23 21:31:42 +02:00
}
}
2021-04-26 21:29:58 +02:00
return cXORMessage;
}
int main(int argc, char* argv[])
{
//parseargs(argc, argv);
xormessage("hello ", "key");
2021-04-23 21:31:42 +02:00
}