Add Arc4 cipher class draft implementation

This commit is contained in:
hashlag
2025-09-16 23:46:24 +03:00
parent 2c21ffea0d
commit e21e36db87
3 changed files with 90 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
#define CHAOS_CIPHER_ARC4CRYPT_HPP
#include "Arc4Gen.hpp"
#include "Service/SeArray.hpp"
#include "Service/ChaosException.hpp"
namespace Chaos::Cipher::Arc4
@@ -29,13 +30,15 @@ public:
template<typename OutputIt, typename InputIt>
void Encrypt(OutputIt out, InputIt in, uint64_t count)
{
// TODO:
EnsureInitialized();
EncryptDecryptImpl(out, in, count);
}
template<typename OutputIt, typename InputIt>
void Decrypt(OutputIt out, InputIt in, uint64_t count)
{
// TODO:
EnsureInitialized();
EncryptDecryptImpl(out, in, count);
}
private:
@@ -56,6 +59,25 @@ private:
Gen_.Rekey(keyBegin, keyEnd);
IsInitialized_ = true;
}
template<typename OutputIt, typename InputIt>
void EncryptDecryptImpl(OutputIt out, InputIt in, uint64_t count)
{
Service::SeArray<uint8_t, 512> keyBuf;
while (count > 0)
{
uint64_t keyMaterialBytes = std::min(keyBuf.Size(), count);
Gen_.Generate(keyBuf.Begin(), keyMaterialBytes);
for (auto keyBufIt = keyBuf.Begin();
keyMaterialBytes > 0 && count > 0;
++keyBufIt, --keyMaterialBytes, --count)
{
*out++ = *in++ ^ *keyBufIt;
}
}
}
};
} // namespace Chaos::Cipher::Arc4