资源简介
全同态加密算法的实现!
运行环境:linux,实现代码需要安装gcc,g++,gmp库。
代码片段和文件信息
#include
#include
#include
NTL_START_IMPL
long ZZ::HexOutput = 0;
const ZZ& ZZ::zero()
{
static ZZ z;
return z;
}
const ZZ& ZZ_expo(long e)
{
static ZZ expo_helper;
conv(expo_helper e);
return expo_helper;
}
void AddMod(ZZ& x const ZZ& a long b const ZZ& n)
{
static ZZ B;
conv(B b);
AddMod(x a B n);
}
void SubMod(ZZ& x const ZZ& a long b const ZZ& n)
{
static ZZ B;
conv(B b);
SubMod(x a B n);
}
void SubMod(ZZ& x long a const ZZ& b const ZZ& n)
{
static ZZ A;
conv(A a);
SubMod(x A b n);
}
// ****** input and output
static long iodigits = 0;
static long ioradix = 0;
// iodigits is the greatest integer such that 10^{iodigits} < NTL_WSP_BOUND
// ioradix = 10^{iodigits}
static void InitZZIO()
{
long x;
x = (NTL_WSP_BOUND-1)/10;
iodigits = 0;
ioradix = 1;
while (x) {
x = x / 10;
iodigits++;
ioradix = ioradix * 10;
}
if (iodigits <= 0) Error(“problem with I/O“);
}
static long HexTwoChars(long &byte istream& s)
{
byte = CharToIntVal(s.peek());
if (byte < 0 || byte > 15)
return 0; // didn‘t read anything from stream
s.get();
long c2 = CharToIntVal(s.peek());
if (c2 < 0 || c2 > 15)
return 1; // read only one character
s.get();
byte <<= 4;
byte += c2;
return 2; // read two characters
}
static void HexReadFromStream(istream& s ZZ& a)
{
const long bufLen = 256; // read upto 256 bytes at a time
static ZZ b;
static unsigned char buf[bufLen];
long nRead;
long bufIdx = bufLen-1;
long c = CharToIntVal(s.peek());
if (c < 0 || c > 15) Error(“HexReadFromStream: bad ZZ input“);
a = 0;
while ((nRead=HexTwoChars(cs)) == 2) { // read next 1-2 chars from stream
buf[bufIdx] = (unsigned char) c;
if (bufIdx == 0) { // buffer is full process it
ZZFromBytes(b buf bufLen);
a <<= bufLen*8; // shift a to left then add b
a += b;
bufIdx = bufLen-1;
}
else bufIdx--;
}
if (bufIdx < bufLen-1) { // get leftovers from buffer
long nBytes = bufLen-bufIdx-1;
ZZFromBytes(b &buf[bufIdx+1] nBytes);
a <<= nBytes*8;
a += b;
}
if (nRead == 1) { // one more character to process
a <<= 4;
a += c;
}
}
istream& operator>>(istream& s ZZ& x)
{
long c;
long cval;
long sign;
long ndigits;
long acc;
static ZZ a;
if (!s) Error(“bad ZZ input (no stream found)“);
if (!iodigits) InitZZIO();
SkipWhiteSpace(s);
c = s.peek();
if (c == ‘-‘) {
sign = -1;
s.get();
c = s.peek();
}
else
sign = 1;
cval = CharToIntVal(c);
if (cval < 0 || cval > 9) Error(“bad ZZ input (first digit not int [0-9])“);
if (c == ‘0‘) { // check if the next char is ‘x‘ else ignore leading 0
s.get();
c = s.peek();
if (c == ‘x‘ || c == ‘X‘) { // hexadecimal number
s.get();
HexReadFromStream(s a);
if (sign == -1) negate(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 764 2010-08-04 16:40 fhe-code\fhe-dec.cc
文件 5154 2010-08-04 16:40 fhe-code\fhe-enc.cc
文件 9389 2010-08-04 16:40 fhe-code\fhe-keygen.cc
文件 10294 2010-08-04 16:40 fhe-code\fhe-recrypt.cc
文件 5997 2010-08-04 16:40 fhe-code\fhe-utils.cc
文件 5872 2010-08-04 16:41 fhe-code\fhe.h
文件 547 2010-07-19 21:31 fhe-code\makefile
文件 203 2010-07-22 15:18 fhe-code\mkflags
文件 652 2010-08-04 16:40 fhe-code\randomStuff.cc
文件 1540 2010-08-04 16:40 fhe-code\randomStuff.h
文件 3355 2010-08-04 16:40 fhe-code\test-recrypt.cc
文件 44093 2010-07-19 16:50 fhe-code\ZZ.c
文件 46837 2010-07-19 16:51 fhe-code\ZZ.h
目录 0 2016-06-27 09:26 fhe-code
----------- --------- ---------- ----- ----
134697 14
- 上一篇:TFGEN.rarTFGEN
- 下一篇:360悬浮窗demo
评论
共有 条评论