資源簡介
IBM的全同態加密代碼,很不錯,有助于理解

代碼片段和文件信息
#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}?//?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?????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?20:40??fhe-dec.cc
?????文件????????5154??2010-08-04?20:40??fhe-enc.cc
?????文件????????9389??2010-08-04?20:40??fhe-keygen.cc
?????文件???????10294??2010-08-04?20:40??fhe-recrypt.cc
?????文件????????5997??2010-08-04?20:40??fhe-utils.cc
?????文件????????5872??2010-08-04?20:41??fhe.h
?????文件?????????547??2010-07-20?01:31??makefile
?????文件?????????203??2010-07-22?19:18??mkflags
?????文件?????????652??2010-08-04?20:40??randomStuff.cc
?????文件????????1540??2010-08-04?20:40??randomStuff.h
?????文件????????3355??2010-08-04?20:40??test-recrypt.cc
?????文件???????44093??2010-07-19?20:50??ZZ.c
?????文件???????46837??2010-07-19?20:51??ZZ.h
評論
共有 條評論