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

📄 mod_exp.cpp

📁 含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种CheckSum校验、多种MAC校验等几十种加密算法的程序
💻 CPP
字号:
/************************************************** Modular Exponentiation Source File             ** (C) 1999-2002 The Botan Project                **************************************************/#include <botan/mod_exp.h>#include <botan/barrett.h>#include <botan/numthry.h>namespace Botan {/************************************************** Fixed Exponent Exponentiation                  **************************************************/BigInt FixedExponent_Exp::power_mod(const BigInt& base) const   {   return Botan::power_mod(reducer->reduce(base), exponent, reducer);   }/************************************************** FixedExponent_Exp Assignment Operator          **************************************************/FixedExponent_Exp& FixedExponent_Exp::operator=(const FixedExponent_Exp& exp)   {   reducer = new BarrettReducer(exp.get_modulus());   exponent = exp.get_exponent();   return (*this);   }/************************************************** FixedExponent_Exp Constructor                  **************************************************/FixedExponent_Exp::FixedExponent_Exp(const BigInt& exp, const BigInt& mod) :   reducer(new BarrettReducer(mod)), exponent(exp)   {   if(mod <= 0)      throw Invalid_Argument("FixedExponent_Exp: Invalid modulus");   if(exp < 0)      throw Invalid_Argument("FixedExponent_Exp: Invalid exponent");   }/************************************************** FixedExponent_Exp Copy Constructor             **************************************************/FixedExponent_Exp::FixedExponent_Exp(const FixedExponent_Exp& exp)   {   exponent = exp.get_exponent();   reducer = new BarrettReducer(exp.get_modulus());   }/************************************************** Fixed Base Exponentiation                      **************************************************/BigInt FixedBase_Exp::power_mod(const BigInt& exp) const   {   if(exp.is_negative())      throw Invalid_Argument("power_mod: exponent must be positive");   if(exp.is_zero())      return BigInt::one();   const u32bit exp_bytes = (exp.bits() + 7) / 8;   BigInt x = 1;   for(u32bit j = exp_bytes; j > 0; j--)      {      for(u32bit k = 0; k != 8; k++)         x = reducer->square(x);      byte nibble = exp.byte_at(j-1);      if(nibble)         x = reducer->multiply(x, g[nibble-1]);      }   return x;   }/************************************************** FixedBase_Exp Assignment Operator              **************************************************/FixedBase_Exp& FixedBase_Exp::operator=(const FixedBase_Exp& exp)   {   reducer = new BarrettReducer(exp.get_modulus());   g = exp.g;   return (*this);   }/************************************************** FixedBase_Exp Constructor                      **************************************************/FixedBase_Exp::FixedBase_Exp(const BigInt& base, const BigInt& mod) :   reducer(new BarrettReducer(mod)), g(255)   {   if(mod <= 0)      throw Invalid_Argument("FixedBase_Exp: Invalid modulus");   if(base < 0)      throw Invalid_Argument("FixedBase_Exp: Invalid base");   g[0] = base;   for(u32bit j = 1; j != g.size(); j++)      g[j] = reducer->multiply(g[j-1], base);   }/************************************************** FixedBase_Exp Copy Constructor                 **************************************************/FixedBase_Exp::FixedBase_Exp(const FixedBase_Exp& exp) :   reducer(new BarrettReducer(exp.get_modulus())), g(exp.g)   {   }}

⌨️ 快捷键说明

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