1 Star 0 Fork 0

bubuzi_tool/cryptopp870

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
blumshub.cpp 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
布布子 提交于 2022-12-12 16:37 . 初始化提交
// blumshub.cpp - originally written and placed in the public domain by Wei Dai
#include "pch.h"
#include "blumshub.h"
#include "integer.h"
NAMESPACE_BEGIN(CryptoPP)
PublicBlumBlumShub::PublicBlumBlumShub(const Integer &n, const Integer &seed)
: modn(n),
current(modn.Square(modn.Square(seed))),
maxBits(BitPrecision(n.BitCount())-1),
bitsLeft(maxBits)
{
}
unsigned int PublicBlumBlumShub::GenerateBit()
{
if (bitsLeft==0)
{
current = modn.Square(current);
bitsLeft = maxBits;
}
return static_cast<unsigned int>(current.GetBit(--bitsLeft));
}
byte PublicBlumBlumShub::GenerateByte()
{
byte b=0;
for (int i=0; i<8; i++)
b = byte((b << 1) | PublicBlumBlumShub::GenerateBit());
return b;
}
void PublicBlumBlumShub::GenerateBlock(byte *output, size_t size)
{
while (size--)
*output++ = PublicBlumBlumShub::GenerateByte();
}
void PublicBlumBlumShub::ProcessData(byte *outString, const byte *inString, size_t length)
{
while (length--)
*outString++ = *inString++ ^ PublicBlumBlumShub::GenerateByte();
}
BlumBlumShub::BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed)
: PublicBlumBlumShub(p*q, seed),
p(p), q(q),
x0(modn.Square(seed))
{
}
void BlumBlumShub::Seek(lword index)
{
Integer i(Integer::POSITIVE, index);
i *= 8;
Integer e = a_exp_b_mod_c (2, i / maxBits + 1, (p-1)*(q-1));
current = modn.Exponentiate(x0, e);
bitsLeft = maxBits - i % maxBits;
}
NAMESPACE_END
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/bubuzi_tool/cryptopp870.git
git@gitee.com:bubuzi_tool/cryptopp870.git
bubuzi_tool
cryptopp870
cryptopp870
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385