From be1049db936e1e328f61f380657235b55570338f Mon Sep 17 00:00:00 2001 From: Orange Date: Sun, 4 Jan 2026 11:50:32 +0300 Subject: [PATCH] changed algorithm --- include/omath/containers/encrypted_variable.hpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/include/omath/containers/encrypted_variable.hpp b/include/omath/containers/encrypted_variable.hpp index 6388fcb..dbd7fcf 100644 --- a/include/omath/containers/encrypted_variable.hpp +++ b/include/omath/containers/encrypted_variable.hpp @@ -125,18 +125,16 @@ namespace omath { std::span bytes{reinterpret_cast(&m_data), sizeof(m_data)}; - for (auto& byte : bytes) - for (const auto key_byte : key) - byte ^= key_byte; + for (size_t i = 0; i < bytes.size(); ++i) + bytes[i] ^= static_cast(key[i % key.size()] + (i * key_size)); m_is_encrypted = false; } - OMATH_FORCEINLINE constexpr void encrypt() + OMATH_FORCEINLINE constexpr void encrypt() { std::span bytes{reinterpret_cast(&m_data), sizeof(m_data)}; - for (auto& byte : bytes) - for (const auto key_byte : key) - byte ^= key_byte; + for (size_t i = 0; i < bytes.size(); ++i) + bytes[i] ^= static_cast(key[i % key.size()] + (i * key_size)); m_is_encrypted = true; } OMATH_FORCEINLINE constexpr T& value() @@ -170,7 +168,6 @@ namespace omath }; } // namespace omath - -#define CT_RAND_ARRAY_INT(N) \ -(::omath::make_array<(N), (::omath::base_seed() ^ static_cast(__COUNTER__))>()) +#define CT_RAND_ARRAY_INT(N) \ + (::omath::make_array<(N), (::omath::base_seed() ^ static_cast(__COUNTER__))>()) #define OMATH_DEF_CRYPT_VAR(TYPE, KEY_SIZE) omath::EncryptedVariable \ No newline at end of file