CXOR/cxor.cpp

96 lines
2.0 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:51:25 +02:00
std::string sIFile;
2021-04-26 21:29:58 +02:00
bool bInputHex = false;
2021-04-26 21:51:25 +02:00
std::string sOFile;
2021-04-26 21:29:58 +02:00
bool bOutputHex = false;
2021-04-26 21:51:25 +02:00
std::string sKey;
2021-04-26 21:29:58 +02:00
po::options_description desc("Allowed options");
desc.add_options()
("help", "Print this message")
2021-04-26 21:33:45 +02:00
("if", po::value<std::string>(), "Specify an input file")
("ih", "Input data is in hex")
2021-04-26 21:33:45 +02:00
("of", po::value<std::string>(), "Specify an output file")
("oh", "Output data in hex")
2021-04-26 21:51:25 +02:00
("k", po::value<std::string>(), "Specify a key")
;
2021-04-26 21:33:45 +02:00
/*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;
}
2021-04-26 21:33:45 +02:00
if (vm.count("if"))
{
2021-04-26 21:51:25 +02:00
sIFile = vm["if"].as<std::string>();
sIFile = sIFile.substr(1, sIFile.length());
}
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:33:45 +02:00
if (vm.count("of"))
{
2021-04-26 21:51:25 +02:00
sOFile = vm["of"].as<std::string>();
sOFile = sOFile.substr(1, sOFile.length());
}
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-26 21:51:25 +02:00
if (vm.count("k"))
{
sKey = vm["k"].as<std::string>();
}
else
{
std::cout << "A key must be specified";
exit(0);
}
}
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
}