亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? gf2n.cpp

?? 此文件是實現加解密算法的函數庫
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
	for (i=0; i<smallerSize; i++)
		if (reg[i] != rhs.reg[i]) return false;

	for (i=smallerSize; i<reg.size(); i++)
		if (reg[i] != 0) return false;

	for (i=smallerSize; i<rhs.reg.size(); i++)
		if (rhs.reg[i] != 0) return false;

	return true;
}

std::ostream& operator<<(std::ostream& out, const PolynomialMod2 &a)
{
	// Get relevant conversion specifications from ostream.
	long f = out.flags() & std::ios::basefield;	// Get base digits.
	int bits, block;
	char suffix;
	switch(f)
	{
	case std::ios::oct :
		bits = 3;
		block = 4;
		suffix = 'o';
		break;
	case std::ios::hex :
		bits = 4;
		block = 2;
		suffix = 'h';
		break;
	default :
		bits = 1;
		block = 8;
		suffix = 'b';
	}

	if (!a)
		return out << '0' << suffix;

	SecBlock<char> s(a.BitCount()/bits+1);
	unsigned i;
	const char vec[]="0123456789ABCDEF";

	for (i=0; i*bits < a.BitCount(); i++)
	{
		int digit=0;
		for (int j=0; j<bits; j++)
			digit |= a[i*bits+j] << j;
		s[i]=vec[digit];
	}

	while (i--)
	{
		out << s[i];
		if (i && (i%block)==0)
			out << ',';
	}

	return out << suffix;
}

PolynomialMod2 PolynomialMod2::Gcd(const PolynomialMod2 &a, const PolynomialMod2 &b)
{
	return EuclideanDomainOf<PolynomialMod2>().Gcd(a, b);
}

PolynomialMod2 PolynomialMod2::InverseMod(const PolynomialMod2 &modulus) const
{
	typedef EuclideanDomainOf<PolynomialMod2> Domain;
	return QuotientRing<Domain>(Domain(), modulus).MultiplicativeInverse(*this);
}

bool PolynomialMod2::IsIrreducible() const
{
	signed int d = Degree();
	if (d <= 0)
		return false;

	PolynomialMod2 t(2), u(t);
	for (int i=1; i<=d/2; i++)
	{
		u = u.Squared()%(*this);
		if (!Gcd(u+t, *this).IsUnit())
			return false;
	}
	return true;
}

// ********************************************************

GF2NP::GF2NP(const PolynomialMod2 &modulus)
	: QuotientRing<EuclideanDomainOf<PolynomialMod2> >(EuclideanDomainOf<PolynomialMod2>(), modulus), m(modulus.Degree()) 
{
}

GF2NP::Element GF2NP::SquareRoot(const Element &a) const
{
	Element r = a;
	for (unsigned int i=1; i<m; i++)
		r = Square(r);
	return r;
}

GF2NP::Element GF2NP::HalfTrace(const Element &a) const
{
	assert(m%2 == 1);
	Element h = a;
	for (unsigned int i=1; i<=(m-1)/2; i++)
		h = Add(Square(Square(h)), a);
	return h;
}

GF2NP::Element GF2NP::SolveQuadraticEquation(const Element &a) const
{
	if (m%2 == 0)
	{
		Element z, w;
		do
		{
			LC_RNG rng(11111);
			Element p(rng, m);
			z = PolynomialMod2::Zero();
			w = p;
			for (unsigned int i=1; i<=m-1; i++)
			{
				w = Square(w);
				z = Square(z);
				Accumulate(z, Multiply(w, a));
				Accumulate(w, p);
			}
		} while (w.IsZero());
		return z;
	}
	else
		return HalfTrace(a);
}

// ********************************************************

GF2NT::GF2NT(unsigned int t0, unsigned int t1, unsigned int t2)
	: GF2NP(PolynomialMod2::Trinomial(t0, t1, t2))
	, t0(t0), t1(t1)
	, result((word)0, m)
{
	assert(t0 > t1 && t1 > t2 && t2==0);
}

const GF2NT::Element& GF2NT::MultiplicativeInverse(const Element &a) const
{
	if (t0-t1 < WORD_BITS)
		return GF2NP::MultiplicativeInverse(a);

	SecWordBlock T(m_modulus.reg.size() * 4);
	word *b = T;
	word *c = T+m_modulus.reg.size();
	word *f = T+2*m_modulus.reg.size();
	word *g = T+3*m_modulus.reg.size();
	unsigned int bcLen=1, fgLen=m_modulus.reg.size();
	unsigned int k=0;

	SetWords(T, 0, 3*m_modulus.reg.size());
	b[0]=1;
	assert(a.reg.size() <= m_modulus.reg.size());
	CopyWords(f, a.reg, a.reg.size());
	CopyWords(g, m_modulus.reg, m_modulus.reg.size());

	while (1)
	{
		word t=f[0];
		while (!t)
		{
			ShiftWordsRightByWords(f, fgLen, 1);
			if (c[bcLen-1])
				bcLen++;
			assert(bcLen <= m_modulus.reg.size());
			ShiftWordsLeftByWords(c, bcLen, 1);
			k+=WORD_BITS;
			t=f[0];
		}

		unsigned int i=0;
		while (t%2 == 0)
		{
			t>>=1;
			i++;
		}
		k+=i;

		if (t==1 && CountWords(f, fgLen)==1)
			break;

		if (i==1)
		{
			ShiftWordsRightByBits(f, fgLen, 1);
			t=ShiftWordsLeftByBits(c, bcLen, 1);
		}
		else
		{
			ShiftWordsRightByBits(f, fgLen, i);
			t=ShiftWordsLeftByBits(c, bcLen, i);
		}
		if (t)
		{
			c[bcLen] = t;
			bcLen++;
			assert(bcLen <= m_modulus.reg.size());
		}

		if (f[fgLen-1]==0 && g[fgLen-1]==0)
			fgLen--;

		if (f[fgLen-1] < g[fgLen-1])
		{
			std::swap(f, g);
			std::swap(b, c);
		}

		XorWords(f, g, fgLen);
		XorWords(b, c, bcLen);
	}

	while (k >= WORD_BITS)
	{
		word temp = b[0];
		// right shift b
		for (unsigned i=0; i+1<BitsToWords(m); i++)
			b[i] = b[i+1];
		b[BitsToWords(m)-1] = 0;

		if (t1 < WORD_BITS)
			for (unsigned int j=0; j<WORD_BITS-t1; j++)
				temp ^= ((temp >> j) & 1) << (t1 + j);
		else
			b[t1/WORD_BITS-1] ^= temp << t1%WORD_BITS;

		if (t1 % WORD_BITS)
			b[t1/WORD_BITS] ^= temp >> (WORD_BITS - t1%WORD_BITS);

		if (t0%WORD_BITS)
		{
			b[t0/WORD_BITS-1] ^= temp << t0%WORD_BITS;
			b[t0/WORD_BITS] ^= temp >> (WORD_BITS - t0%WORD_BITS);
		}
		else
			b[t0/WORD_BITS-1] ^= temp;

		k -= WORD_BITS;
	}

	if (k)
	{
		word temp = b[0] << (WORD_BITS - k);
		ShiftWordsRightByBits(b, BitsToWords(m), k);

		if (t1 < WORD_BITS)
			for (unsigned int j=0; j<WORD_BITS-t1; j++)
				temp ^= ((temp >> j) & 1) << (t1 + j);
		else
			b[t1/WORD_BITS-1] ^= temp << t1%WORD_BITS;

		if (t1 % WORD_BITS)
			b[t1/WORD_BITS] ^= temp >> (WORD_BITS - t1%WORD_BITS);

		if (t0%WORD_BITS)
		{
			b[t0/WORD_BITS-1] ^= temp << t0%WORD_BITS;
			b[t0/WORD_BITS] ^= temp >> (WORD_BITS - t0%WORD_BITS);
		}
		else
			b[t0/WORD_BITS-1] ^= temp;
	}

	CopyWords(result.reg.begin(), b, result.reg.size());
	return result;
}

const GF2NT::Element& GF2NT::Multiply(const Element &a, const Element &b) const
{
	unsigned int aSize = STDMIN(a.reg.size(), result.reg.size());
	Element r((word)0, m);

	for (int i=m-1; i>=0; i--)
	{
		if (r[m-1])
		{
			ShiftWordsLeftByBits(r.reg.begin(), r.reg.size(), 1);
			XorWords(r.reg.begin(), m_modulus.reg, r.reg.size());
		}
		else
			ShiftWordsLeftByBits(r.reg.begin(), r.reg.size(), 1);

		if (b[i])
			XorWords(r.reg.begin(), a.reg, aSize);
	}

	if (m%WORD_BITS)
		r.reg.begin()[r.reg.size()-1] = (word)Crop(r.reg[r.reg.size()-1], m%WORD_BITS);

	CopyWords(result.reg.begin(), r.reg.begin(), result.reg.size());
	return result;
}

const GF2NT::Element& GF2NT::Reduced(const Element &a) const
{
	if (t0-t1 < WORD_BITS)
		return m_domain.Mod(a, m_modulus);

	SecWordBlock b(a.reg);

	unsigned i;
	for (i=b.size()-1; i>=BitsToWords(t0); i--)
	{
		word temp = b[i];

		if (t0%WORD_BITS)
		{
			b[i-t0/WORD_BITS] ^= temp >> t0%WORD_BITS;
			b[i-t0/WORD_BITS-1] ^= temp << (WORD_BITS - t0%WORD_BITS);
		}
		else
			b[i-t0/WORD_BITS] ^= temp;

		if ((t0-t1)%WORD_BITS)
		{
			b[i-(t0-t1)/WORD_BITS] ^= temp >> (t0-t1)%WORD_BITS;
			b[i-(t0-t1)/WORD_BITS-1] ^= temp << (WORD_BITS - (t0-t1)%WORD_BITS);
		}
		else
			b[i-(t0-t1)/WORD_BITS] ^= temp;
	}

	if (i==BitsToWords(t0)-1 && t0%WORD_BITS)
	{
		word mask = ((word)1<<(t0%WORD_BITS))-1;
		word temp = b[i] & ~mask;
		b[i] &= mask;

		b[i-t0/WORD_BITS] ^= temp >> t0%WORD_BITS;

		if ((t0-t1)%WORD_BITS)
		{
			b[i-(t0-t1)/WORD_BITS] ^= temp >> (t0-t1)%WORD_BITS;
			if ((t0-t1)%WORD_BITS > t0%WORD_BITS)
				b[i-(t0-t1)/WORD_BITS-1] ^= temp << (WORD_BITS - (t0-t1)%WORD_BITS);
			else
				assert(temp << (WORD_BITS - (t0-t1)%WORD_BITS) == 0);
		}
		else
			b[i-(t0-t1)/WORD_BITS] ^= temp;
	}

	SetWords(result.reg.begin(), 0, result.reg.size());
	CopyWords(result.reg.begin(), b, STDMIN(b.size(), result.reg.size()));
	return result;
}

void GF2NP::DEREncodeElement(BufferedTransformation &out, const Element &a) const
{
	a.DEREncodeAsOctetString(out, MaxElementByteLength());
}

void GF2NP::BERDecodeElement(BufferedTransformation &in, Element &a) const
{
	a.BERDecodeAsOctetString(in, MaxElementByteLength());
}

void GF2NT::DEREncode(BufferedTransformation &bt) const
{
	DERSequenceEncoder seq(bt);
		ASN1::characteristic_two_field().DEREncode(seq);
		DERSequenceEncoder parameters(seq);
			DEREncodeUnsigned(parameters, m);
			ASN1::tpBasis().DEREncode(parameters);
			DEREncodeUnsigned(parameters, t1);
		parameters.MessageEnd();
	seq.MessageEnd();
}

void GF2NPP::DEREncode(BufferedTransformation &bt) const
{
	DERSequenceEncoder seq(bt);
		ASN1::characteristic_two_field().DEREncode(seq);
		DERSequenceEncoder parameters(seq);
			DEREncodeUnsigned(parameters, m);
			ASN1::ppBasis().DEREncode(parameters);
			DERSequenceEncoder pentanomial(parameters);
				DEREncodeUnsigned(pentanomial, t3);
				DEREncodeUnsigned(pentanomial, t2);
				DEREncodeUnsigned(pentanomial, t1);
			pentanomial.MessageEnd();
		parameters.MessageEnd();
	seq.MessageEnd();
}

GF2NP * BERDecodeGF2NP(BufferedTransformation &bt)
{
	// VC60 workaround: auto_ptr lacks reset()
	member_ptr<GF2NP> result;

	BERSequenceDecoder seq(bt);
		if (OID(seq) != ASN1::characteristic_two_field())
			BERDecodeError();
		BERSequenceDecoder parameters(seq);
			unsigned int m;
			BERDecodeUnsigned(parameters, m);
			OID oid(parameters);
			if (oid == ASN1::tpBasis())
			{
				unsigned int t1;
				BERDecodeUnsigned(parameters, t1);
				result.reset(new GF2NT(m, t1, 0));
			}
			else if (oid == ASN1::ppBasis())
			{
				unsigned int t1, t2, t3;
				BERSequenceDecoder pentanomial(parameters);
				BERDecodeUnsigned(pentanomial, t3);
				BERDecodeUnsigned(pentanomial, t2);
				BERDecodeUnsigned(pentanomial, t1);
				pentanomial.MessageEnd();
				result.reset(new GF2NPP(m, t3, t2, t1, 0));
			}
			else
			{
				BERDecodeError();
				return NULL;
			}
		parameters.MessageEnd();
	seq.MessageEnd();

	return result.release();
}

NAMESPACE_END

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美视频一区二区| 欧美亚洲综合网| 一本大道久久a久久综合| 欧美一区二区三区喷汁尤物| 亚洲欧洲一区二区在线播放| 裸体在线国模精品偷拍| 日本精品一区二区三区四区的功能| 日韩午夜激情视频| 亚洲不卡av一区二区三区| 国产91对白在线观看九色| 日韩欧美亚洲国产另类| 亚洲一二三区在线观看| 99国内精品久久| 精品99999| 蜜桃精品视频在线| 在线不卡免费av| 亚洲一区二区三区四区不卡| 99精品久久免费看蜜臀剧情介绍| 久久日一线二线三线suv| 日本欧美久久久久免费播放网| 欧美最猛黑人xxxxx猛交| 国产精品久久久久久久蜜臀 | 国产自产视频一区二区三区| 欧美性生活一区| 亚洲免费在线观看| 91麻豆免费看片| 国产精品丝袜91| 国产精品羞羞答答xxdd| 2021中文字幕一区亚洲| 精品一区二区三区在线观看国产| 制服丝袜一区二区三区| 午夜欧美电影在线观看| 欧美一区二区三区婷婷月色| 一区二区三区在线视频观看58| 色综合天天视频在线观看| 综合久久久久久| 日本韩国欧美三级| 亚洲综合在线免费观看| 欧美视频在线播放| 视频一区二区三区中文字幕| 777久久久精品| 亚洲1区2区3区视频| 亚洲va在线va天堂| 51精品国自产在线| 免费一级片91| 久久一日本道色综合| 成人综合在线视频| 夜色激情一区二区| 欧美一区二区三区在线看| 久久精品国产99| 日本一二三不卡| 色综合久久久网| 午夜精品一区在线观看| 欧美mv日韩mv国产| 成人18精品视频| 亚洲影视在线播放| 宅男噜噜噜66一区二区66| 国产在线国偷精品产拍免费yy| 中文成人综合网| 欧美日韩一区 二区 三区 久久精品| 午夜伦理一区二区| 欧美一级免费大片| 国产一区二区在线观看免费| 中文字幕一区二区三中文字幕| 91极品美女在线| 国产一区二区三区蝌蚪| 国产精品久久久久久久蜜臀 | 亚洲成人av免费| 精品sm捆绑视频| 欧美探花视频资源| 国产精品自拍av| 亚洲国产cao| 欧美极品aⅴ影院| 91精品国产一区二区三区香蕉 | 久久久国产精品午夜一区ai换脸| 91免费看片在线观看| 激情伊人五月天久久综合| 亚洲人成在线观看一区二区| 日韩欧美一级精品久久| 在线欧美一区二区| 国产精品伊人色| 五月婷婷综合在线| 亚洲欧洲美洲综合色网| 精品少妇一区二区三区在线播放| 91一区二区在线| 国产精品自产自拍| 日日骚欧美日韩| 亚洲猫色日本管| 国产精品美女久久久久久久久| 69久久夜色精品国产69蝌蚪网| 不卡电影免费在线播放一区| 麻豆精品视频在线观看视频| 一区二区三区中文字幕精品精品| 久久精品人人做人人综合| 7777精品伊人久久久大香线蕉的 | 不卡一区二区三区四区| 老司机午夜精品| 午夜一区二区三区视频| 亚洲免费av观看| 亚洲麻豆国产自偷在线| 综合久久一区二区三区| 欧美激情一区二区| 国产欧美一区二区三区网站 | 国产精品剧情在线亚洲| 久久精品欧美日韩精品| 日韩欧美一级二级三级久久久 | 欧美午夜一区二区三区免费大片| 成av人片一区二区| 成人精品视频网站| 丁香网亚洲国际| av午夜一区麻豆| av在线不卡观看免费观看| 成人av午夜电影| 不卡在线观看av| 色域天天综合网| 在线观看www91| 色94色欧美sute亚洲线路一久| 色婷婷久久久久swag精品| 色综合天天做天天爱| 91精彩视频在线观看| 欧美视频在线观看一区二区| 欧美日韩精品一区二区三区| 欧美性色综合网| 欧美一区永久视频免费观看| 91精品久久久久久蜜臀| 欧美大度的电影原声| 26uuu精品一区二区在线观看| 久久综合九色综合97婷婷女人 | 久久精品理论片| 激情久久五月天| 国产成人啪午夜精品网站男同| 懂色av一区二区三区免费看| av网站免费线看精品| 欧美日韩综合色| 日韩免费观看2025年上映的电影| 日韩精品影音先锋| 欧美激情在线观看视频免费| 亚洲精品久久久蜜桃| 视频精品一区二区| 国产精品18久久久久久久久久久久| 国v精品久久久网| 在线视频欧美区| 精品久久国产97色综合| 国产精品欧美久久久久一区二区| 亚洲欧洲中文日韩久久av乱码| 亚洲sss视频在线视频| 激情亚洲综合在线| 一本久道久久综合中文字幕| 91精品一区二区三区在线观看| 久久精品在线免费观看| 一区二区三区四区视频精品免费| 美女网站一区二区| 波多野结衣中文字幕一区 | 2019国产精品| 亚洲精品精品亚洲| 精品伊人久久久久7777人| 成人自拍视频在线观看| 欧美精品日日鲁夜夜添| 中文字幕av一区二区三区免费看 | 在线这里只有精品| 亚洲精品一区二区三区精华液| 中文字幕一区二区5566日韩| 日韩激情一区二区| 99久久精品免费| 欧美v日韩v国产v| 一区二区三区日韩欧美| 国产精品综合在线视频| 欧美三级电影一区| 中文字幕视频一区| 久久精品国产亚洲a| 欧美日韩一区成人| 亚洲美女偷拍久久| 国产精品亚洲专一区二区三区| 欧美精品vⅰdeose4hd| 亚洲色图20p| 国产成人av一区| 精品国偷自产国产一区| 亚洲a一区二区| 欧美影院精品一区| 亚洲美女在线一区| 岛国精品一区二区| 久久婷婷国产综合精品青草 | 亚洲综合精品自拍| 成人高清视频免费观看| 久久这里都是精品| 精品影视av免费| 日韩视频在线观看一区二区| 亚洲国产精品一区二区www在线 | 国产精品视频一二三区| 精品一区二区三区蜜桃| 91精品久久久久久久91蜜桃| 亚洲国产一二三| 欧美伊人久久久久久久久影院 | 成人免费不卡视频| 国产亚洲欧洲997久久综合| 麻豆中文一区二区| 精品久久久网站| 久久99精品一区二区三区| 日韩精品一区二区三区在线观看| 青青草国产成人99久久|