#include #include #include #include "Cipher/Arc4/Arc4Crypt.hpp" using namespace Chaos::Cipher::Arc4; static std::vector StrToU8Vec(const char * str) { std::vector result; result.reserve(strlen(str)); for (; *str != '\0'; ++str) { result.push_back(static_cast(*str)); } return result; } static std::string U8VecToStr(const std::vector & vec) { std::string result; result.reserve(vec.size()); for (auto it = vec.begin(); it != vec.end(); ++it) { result.push_back(static_cast(*it)); } return result; } TEST(Arc4CryptTests, BasicTest) { const std::vector key = StrToU8Vec("Secret"); const std::vector data = StrToU8Vec("Attack at dawn"); std::vector ciphertext; ciphertext.resize(data.size()); { Arc4Crypt arc4; arc4.Rekey(key.begin(), key.end()); arc4.Encrypt(ciphertext.begin(), data.begin(), data.size()); } ASSERT_EQ(std::vector({ 0x45, 0xA0, 0x1F, 0x64, 0x5F, 0xC3, 0x5B, 0x38, 0x35, 0x52, 0x54, 0x4B, 0x9B, 0xF5 }), ciphertext); std::vector recoveredData; recoveredData.resize(data.size()); { Arc4Crypt arc4; arc4.Rekey(key.begin(), key.end()); arc4.Decrypt(recoveredData.begin(), ciphertext.begin(), ciphertext.size()); } ASSERT_EQ(data, recoveredData); }