添加超大数的实现

master
a7458969 2020-01-07 01:04:21 +08:00
parent a314e0ca77
commit 453274c4d9
6 changed files with 1775 additions and 14 deletions

View File

@ -12,10 +12,11 @@
</component>
<component name="ChangeListManager">
<list default="true" id="0facce0d-c642-4d80-b2fb-daf5f3e68dff" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/obj/inc/rsa.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/obj/inc/rsa.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmake-build-debug/General.cbp" beforeDir="false" afterPath="$PROJECT_DIR$/cmake-build-debug/General.cbp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/obj/inc/rsa.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/obj/inc/rsa.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/obj/inc/rsa.h" beforeDir="false" afterPath="$PROJECT_DIR$/obj/inc/rsa.h" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
@ -84,7 +85,7 @@
<workItem from="1577933660908" duration="635000" />
<workItem from="1578153114620" duration="4070000" />
<workItem from="1578225965728" duration="1215000" />
<workItem from="1578280389789" duration="7997000" />
<workItem from="1578280389789" duration="12145000" />
</task>
<servers />
</component>

View File

@ -6,7 +6,8 @@ INCLUDE_DIRECTORIES (inc)
aux_source_directory(src DIRSRCS)
aux_source_directory(src/pattern PaternSrc)
add_library(General ${DIRSRCS} ${PaternSrc} src/pattern/signleton.h src/pattern/Observer.h src/pattern/stratergy.h src/pattern/adapter.h src/encrypt/base64.cpp src/encrypt/base64.h src/encrypt/aes.cpp src/encrypt/aes.h obj/inc/rsa.cpp obj/inc/rsa.h)
add_library(General ${DIRSRCS} ${PaternSrc} src/pattern/signleton.h src/pattern/Observer.h src/pattern/stratergy.h src/pattern/adapter.h src/encrypt/base64.cpp src/encrypt/base64.h src/encrypt/aes.cpp src/encrypt/aes.h obj/inc/rsa.cpp obj/inc/rsa.h
src/math/BigInt.hpp)
set(COPYITEM inc)
file(GLOB INCLUDES ${PROJECT_SOURCE_DIR}/inc/*)
file(COPY ${INCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc
@ -20,3 +21,7 @@ file(COPY ${PatternINCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc
file(GLOB EncryptINCLUDES ${PROJECT_SOURCE_DIR}/src/encrypt/*.h)
file(COPY ${EncryptINCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ)
file(GLOB MathINCLUDES ${PROJECT_SOURCE_DIR}/src/encrypt/*.hpp)
file(COPY ${MathINCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ)

View File

@ -108,6 +108,9 @@
<Unit filename="D:/project/c++/generallib/src/loger.cpp">
<Option target="General"/>
</Unit>
<Unit filename="D:/project/c++/generallib/src/math/BigInt.hpp">
<Option target="General"/>
</Unit>
<Unit filename="D:/project/c++/generallib/src/pattern/Observer.h">
<Option target="General"/>
</Unit>

View File

@ -68,6 +68,18 @@ const static int PrimeTable[550]=
3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001
};
static int Mod(uint8_t *dat,int size,int table){
}
/*
apa,p(1)a(p-1)p1
, p, a<p,
a ^ p % p == a
1/2
,
, ln(x), , n bit, , , , n,
*/
BigInt GetPrime(int bits)
{
unsigned i;
@ -88,8 +100,8 @@ BigInt GetPrime(int bits)
m_ulValue[0]++;
for(i = 0; i <550;i++)
{
//if(Mod(PrimeTable[i]) == 0)
// goto begin;
if(Mod(PrimeTable[i]) == 0)
goto begin;
}
//CBigInt S,A,I,K;
//K.Mov(*this);
@ -181,15 +193,16 @@ bool rabinmiller(size_t n, size_t k)
}
BigInt::BigInt(int size) {
memset(this->mDat,0,size);
}
BigInt::BigInt(int size, uint8_t *dat) {
memcpy(this->mDat,dat,size);
}
BigInt BigInt::operator=(const BigInt &) {
return BigInt(0);
bool BigInt::operator=(BigInt &cmp) {
return memcmp((const void *)cmp.Data(),
(const void *)this->Data(),this->mSize);
}
BigInt BigInt::operator>(const BigInt &) {
@ -208,6 +221,6 @@ string BigInt::ToString() {
return std::__cxx11::string();
}
uint8_t *BigInt::Data() {
const uint8_t *BigInt::Data() {
return mDat;
}

View File

@ -13,12 +13,12 @@ class BigInt{
public:
BigInt(int size);
BigInt(int size,uint8_t *dat);
BigInt operator=(const BigInt&);
bool operator=(BigInt&);
BigInt operator>(const BigInt&);
BigInt operator<(const BigInt&);
BigInt operator^(const BigInt&);
string ToString();
uint8_t *Data();
const uint8_t *Data();
private:
uint8_t mDat[2048];
int mSize;

1739
src/math/BigInt.hpp Normal file

File diff suppressed because it is too large Load Diff