本文整理汇总了C++中cryptopp::Integer::BitCount方法的典型用法代码示例。如果您正苦于以下问题:C++ Integer::BitCount方法的具体用法?C++ Integer::BitCount怎么用?C++ Integer::BitCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptopp::Integer
的用法示例。
在下文中一共展示了Integer::BitCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: invalid_argument
const vector<unsigned char> CryptoPpDlogZpSafePrime::decodeGroupElementToByteArray(GroupElement * groupElement) {
ZpSafePrimeElementCryptoPp * zp_element = dynamic_cast<ZpSafePrimeElementCryptoPp *>(groupElement);
if (!(zp_element))
throw invalid_argument("element type doesn't match the group type");
//Given a group element y, find the two inverses z,-z. Take z to be the value between 1 and (p-1)/2. Return s=z-1
biginteger y = zp_element->getElementValue();
biginteger p = ((ZpGroupParams * ) groupParams)->getP();
MathAlgorithms::SquareRootResults roots = MathAlgorithms::sqrtModP_3_4(y, p);
biginteger goodRoot;
biginteger halfP = (p - 1) / 2;
if (roots.getRoot1()>1 && roots.getRoot1() < halfP)
goodRoot = roots.getRoot1();
else
goodRoot = roots.getRoot2();
goodRoot -= 1;
CryptoPP::Integer cpi = biginteger_to_cryptoppint(goodRoot);
int len = ceil((cpi.BitCount() + 1) / 8.0); //ceil(find_log2_floor(goodRoot) / 8.0);
byte * output = new byte[len];
cpi.Encode(output, len);
vector<byte> res;
// Remove the padding byte at the most significant position (that was added while encoding)
for (int i = 1; i < len; ++i)
res.push_back(output[i]);
return res;
}
示例2: Mul
CryptoPP::ECP::Point Mul (const CryptoPP::ECP::Point& p, const CryptoPP::Integer& e) const
{
CryptoPP::ECP::Point res {0, 1};
if (!e.IsZero ())
{
auto bitCount = e.BitCount ();
for (int i = bitCount - 1; i >= 0; i--)
{
res = Sum (res, res);
if (e.GetBit (i)) res = Sum (res, p);
}
}
return res;
}