⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 barrett.cpp

📁 含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种CheckSum校验、多种MAC校验等几十种加密算法的程序
💻 CPP
字号:
/************************************************** Barrett Reducer Source File                    ** (C) 1999-2002 The Botan Project                **************************************************/#include <botan/barrett.h>#include <botan/numthry.h>#include <botan/mp_types.h>namespace Botan {/************************************************** Precompute values                              **************************************************/BarrettReducer::BarrettReducer(const BigInt& mod) : ModularReducer(mod)   {   if(modulus <= 0)      throw Invalid_Argument("BarrettReducer: Modulus must be > 0");   k = modulus.sig_words();   mu.set_bit(MP_WORD_BITS * 2 * k);   mu /= modulus;   max_bits = MP_WORD_BITS * 2 * k;   b_to_k1.set_bit(MP_WORD_BITS * (k+1));   if(mu.size() > 16)      mu.grow_reg((2 << (high_bit(mu.size()) - 1)) - mu.size());   }/************************************************** Compute a remainder                            **************************************************/BigInt BarrettReducer::reduce(const BigInt& n) const   {   if(n.is_positive() && n < modulus)      return n;   if(n.bits() > max_bits)      return (n % modulus);   a = n;   a.set_sign(Positive);   a >>= (MP_WORD_BITS * (k - 1));   a *= mu;   a >>= (MP_WORD_BITS * (k + 1));   a *= modulus;   for(u32bit j = k + 1; j < a.size(); j++)      a[j] = 0;   b = n;   b.set_sign(Positive);   for(u32bit j = k + 1; j < b.size(); j++)      b[j] = 0;   b -= a;   if(b.is_negative())      b += b_to_k1;   while(b >= modulus)      b -= modulus;   if(n.is_negative() && b.is_nonzero())      { b = modulus - b; }   return b;   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -