// c++ standard : c++20
#include <bit>
#include <type_traits>
template <typename T1, typename T2,
typename RT = std::make_unsigned_t<
std::conditional_t<sizeof(T1) >= sizeof(T2), T1, T2>>>
RT GF2_mod(T1 x, const T2 p) // computes x mod p in GF(2^m)
{
RT y = static_cast<RT>(x);
while (x && std::countl_zero(x) <= std::countl_zero(p))
{
y ^= (static_cast<RT>(p) << (std::countl_zero(p) - std::countl_zero(x)));
}
return y;
}
扩展域GF(2^m)在特定不可约多项式下取余运算的C++实现
最新推荐文章于 2023-03-21 18:19:03 发布