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

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

?? polynomi.cpp

?? 加密函數庫:包括多種加密解密算法,數字簽名,散列算法
?? CPP
字號:
// polynomi.cpp - written and placed in the public domain by Wei Dai

// Part of the code for polynomial evaluation and interpolation
// originally came from Hal Finney's public domain secsplit.c.

#include "pch.h"
#include "polynomi.h"
#include "secblock.h"

#include <strstream>
#include <iostream>

NAMESPACE_BEGIN(CryptoPP)

template <class T>
void PolynomialOver<T>::Randomize(RandomNumberGenerator &rng, const RandomizationParameter &parameter, const Ring &ring)
{
	m_coefficients.resize(parameter.m_coefficientCount);
	for (unsigned int i=0; i<m_coefficients.size(); ++i)
		m_coefficients[i] = ring.RandomElement(rng, parameter.m_coefficientParameter);
}

template <class T>
void PolynomialOver<T>::FromStr(const char *str, const Ring &ring)
{
	std::istrstream in((char *)str);
	bool positive = true;
	CoefficientType coef;
	unsigned int power;

	while (in)
	{
		std::ws(in);
		if (in.peek() == 'x')
			coef = ring.MultiplicativeIdentity();
		else
			in >> coef;

		std::ws(in);
		if (in.peek() == 'x')
		{
			in.get();
			std::ws(in);
			if (in.peek() == '^')
			{
				in.get();
				in >> power;
			}
			else
				power = 1;
		}
		else
			power = 0;

		if (!positive)
			coef = ring.Inverse(coef);

		SetCoefficient(power, coef, ring);

		std::ws(in);
		switch (in.get())
		{
		case '+':
			positive = true;
			break;
		case '-':
			positive = false;
			break;
		default:
			return;		// something's wrong with the input string
		}
	}
}

template <class T>
unsigned int PolynomialOver<T>::CoefficientCount(const Ring &ring) const
{
	unsigned count = m_coefficients.size();
	while (count && ring.Equal(m_coefficients[count-1], ring.Identity()))
		count--;
	const_cast<std::vector<CoefficientType> &>(m_coefficients).resize(count);
	return count;
}

template <class T>
typename PolynomialOver<T>::CoefficientType PolynomialOver<T>::GetCoefficient(unsigned int i, const Ring &ring) const 
{
	return (i < m_coefficients.size()) ? m_coefficients[i] : ring.Identity();
}

template <class T>
PolynomialOver<T>&  PolynomialOver<T>::operator=(const PolynomialOver<T>& t)
{
	if (this != &t)
	{
		m_coefficients.resize(t.m_coefficients.size());
		for (unsigned int i=0; i<m_coefficients.size(); i++)
			m_coefficients[i] = t.m_coefficients[i];
	}
	return *this;
}

template <class T>
PolynomialOver<T>& PolynomialOver<T>::Accumulate(const PolynomialOver<T>& t, const Ring &ring)
{
	unsigned int count = t.CoefficientCount(ring);

	if (count > CoefficientCount(ring))
		m_coefficients.resize(count, ring.Identity());

	for (unsigned int i=0; i<count; i++)
		ring.Accumulate(m_coefficients[i], t.GetCoefficient(i, ring));

	return *this;
}

template <class T>
PolynomialOver<T>& PolynomialOver<T>::Reduce(const PolynomialOver<T>& t, const Ring &ring)
{
	unsigned int count = t.CoefficientCount(ring);

	if (count > CoefficientCount(ring))
		m_coefficients.resize(count, ring.Identity());

	for (unsigned int i=0; i<count; i++)
		ring.Reduce(m_coefficients[i], t.GetCoefficient(i, ring));

	return *this;
}

template <class T>
typename PolynomialOver<T>::CoefficientType PolynomialOver<T>::EvaluateAt(const CoefficientType &x, const Ring &ring) const
{
	int degree = Degree(ring);

	if (degree < 0)
		return ring.Identity();

	CoefficientType result = m_coefficients[degree];
	for (int j=degree-1; j>=0; j--)
	{
		result = ring.Multiply(result, x);
		ring.Accumulate(result, m_coefficients[j]);
	}
	return result;
}

template <class T>
PolynomialOver<T>& PolynomialOver<T>::ShiftLeft(unsigned int n, const Ring &ring)
{
	unsigned int i = CoefficientCount(ring) + n;
	m_coefficients.resize(i, ring.Identity());
	while (i > n)
	{
		i--;
		m_coefficients[i] = m_coefficients[i-n];
	}
	while (i)
	{
		i--;
		m_coefficients[i] = ring.Identity();
	}
	return *this;
}

template <class T>
PolynomialOver<T>& PolynomialOver<T>::ShiftRight(unsigned int n, const Ring &ring)
{
	unsigned int count = CoefficientCount(ring);
	if (count > n)
	{
		for (unsigned int i=0; i<count-n; i++)
			m_coefficients[i] = m_coefficients[i+n];
		m_coefficients.resize(count-n, ring.Identity());
	}
	else
		m_coefficients.resize(0, ring.Identity());
	return *this;
}

template <class T>
void PolynomialOver<T>::SetCoefficient(unsigned int i, const CoefficientType &value, const Ring &ring)
{
	if (i >= m_coefficients.size())
		m_coefficients.resize(i+1, ring.Identity());
	m_coefficients[i] = value;
}

template <class T>
void PolynomialOver<T>::Negate(const Ring &ring)
{
	unsigned int count = CoefficientCount(ring);
	for (unsigned int i=0; i<count; i++)
		m_coefficients[i] = ring.Inverse(m_coefficients[i]);
}

template <class T>
void PolynomialOver<T>::swap(PolynomialOver<T> &t)
{
	m_coefficients.swap(t.m_coefficients);
}

template <class T>
bool PolynomialOver<T>::Equals(const PolynomialOver<T>& t, const Ring &ring) const
{
	unsigned int count = CoefficientCount(ring);

	if (count != t.CoefficientCount(ring))
		return false;

	for (unsigned int i=0; i<count; i++)
		if (!ring.Equal(m_coefficients[i], t.m_coefficients[i]))
			return false;

	return true;
}

template <class T>
PolynomialOver<T> PolynomialOver<T>::Plus(const PolynomialOver<T>& t, const Ring &ring) const
{
	unsigned int i;
	unsigned int count = CoefficientCount(ring);
	unsigned int tCount = t.CoefficientCount(ring);

	if (count > tCount)
	{
		PolynomialOver<T> result(ring, count);

		for (i=0; i<tCount; i++)
			result.m_coefficients[i] = ring.Add(m_coefficients[i], t.m_coefficients[i]);
		for (; i<count; i++)
			result.m_coefficients[i] = m_coefficients[i];

		return result;
	}
	else
	{
		PolynomialOver<T> result(ring, tCount);

		for (i=0; i<count; i++)
			result.m_coefficients[i] = ring.Add(m_coefficients[i], t.m_coefficients[i]);
		for (; i<tCount; i++)
			result.m_coefficients[i] = t.m_coefficients[i];

		return result;
	}
}

template <class T>
PolynomialOver<T> PolynomialOver<T>::Minus(const PolynomialOver<T>& t, const Ring &ring) const
{
	unsigned int i;
	unsigned int count = CoefficientCount(ring);
	unsigned int tCount = t.CoefficientCount(ring);

	if (count > tCount)
	{
		PolynomialOver<T> result(ring, count);

		for (i=0; i<tCount; i++)
			result.m_coefficients[i] = ring.Subtract(m_coefficients[i], t.m_coefficients[i]);
		for (; i<count; i++)
			result.m_coefficients[i] = m_coefficients[i];

		return result;
	}
	else
	{
		PolynomialOver<T> result(ring, tCount);

		for (i=0; i<count; i++)
			result.m_coefficients[i] = ring.Subtract(m_coefficients[i], t.m_coefficients[i]);
		for (; i<tCount; i++)
			result.m_coefficients[i] = ring.Inverse(t.m_coefficients[i]);

		return result;
	}
}

template <class T>
PolynomialOver<T> PolynomialOver<T>::Inverse(const Ring &ring) const
{
	unsigned int count = CoefficientCount(ring);
	PolynomialOver<T> result(ring, count);

	for (unsigned int i=0; i<count; i++)
		result.m_coefficients[i] = ring.Inverse(m_coefficients[i]);

	return result;
}

template <class T>
PolynomialOver<T> PolynomialOver<T>::Times(const PolynomialOver<T>& t, const Ring &ring) const
{
	if (IsZero(ring) || t.IsZero(ring))
		return PolynomialOver<T>();

	unsigned int count1 = CoefficientCount(ring), count2 = t.CoefficientCount(ring);
	PolynomialOver<T> result(ring, count1 + count2 - 1);

	for (unsigned int i=0; i<count1; i++)
		for (unsigned int j=0; j<count2; j++)
			ring.Accumulate(result.m_coefficients[i+j], ring.Multiply(m_coefficients[i], t.m_coefficients[j]));

	return result;
}

template <class T>
PolynomialOver<T> PolynomialOver<T>::DividedBy(const PolynomialOver<T>& t, const Ring &ring) const
{
	PolynomialOver<T> remainder, quotient;
	Divide(remainder, quotient, *this, t, ring);
	return quotient;
}

template <class T>
PolynomialOver<T> PolynomialOver<T>::Modulo(const PolynomialOver<T>& t, const Ring &ring) const
{
	PolynomialOver<T> remainder, quotient;
	Divide(remainder, quotient, *this, t, ring);
	return remainder;
}

template <class T>
PolynomialOver<T> PolynomialOver<T>::MultiplicativeInverse(const Ring &ring) const
{
	return Degree(ring)==0 ? ring.MultiplicativeInverse(m_coefficients[0]) : ring.Identity();
}

template <class T>
bool PolynomialOver<T>::IsUnit(const Ring &ring) const
{
	return Degree(ring)==0 && ring.IsUnit(m_coefficients[0]);
}

template <class T>
std::istream& PolynomialOver<T>::Input(std::istream &in, const Ring &ring)
{
	char c;
	unsigned int length = 0;
	SecBlock<char> str(length + 16);
	bool paren = false;

	std::ws(in);

	if (in.peek() == '(')
	{
		paren = true;
		in.get();
	}

	do
	{
		in.read(&c, 1);
		str[length++] = c;
		if (length >= str.size())
			str.Grow(length + 16);
	}
	// if we started with a left paren, then read until we find a right paren,
	// otherwise read until the end of the line
	while (in && ((paren && c != ')') || (!paren && c != '\n')));

	str[length-1] = '\0';
	*this = PolynomialOver<T>(str, ring);

	return in;
}

template <class T>
std::ostream& PolynomialOver<T>::Output(std::ostream &out, const Ring &ring) const
{
	unsigned int i = CoefficientCount(ring);
	if (i)
	{
		bool firstTerm = true;

		while (i--)
		{
			if (m_coefficients[i] != ring.Identity())
			{
				if (firstTerm)
				{
					firstTerm = false;
					if (!i || !ring.Equal(m_coefficients[i], ring.MultiplicativeIdentity()))
						out << m_coefficients[i];
				}
				else
				{
					CoefficientType inverse = ring.Inverse(m_coefficients[i]);
					std::ostrstream pstr, nstr;

					pstr << m_coefficients[i];
					nstr << inverse;

					if (pstr.pcount() <= nstr.pcount())
					{
						out << " + "; 
						if (!i || !ring.Equal(m_coefficients[i], ring.MultiplicativeIdentity()))
							out << m_coefficients[i];
					}
					else
					{
						out << " - "; 
						if (!i || !ring.Equal(inverse, ring.MultiplicativeIdentity()))
							out << inverse;
					}
				}

				switch (i)
				{
				case 0:
					break;
				case 1:
					out << "x";
					break;
				default:
					out << "x^" << i;
				}
			}
		}
	}
	else
	{
		out << ring.Identity();
	}
	return out;
}

template <class T>
void PolynomialOver<T>::Divide(PolynomialOver<T> &r, PolynomialOver<T> &q, const PolynomialOver<T> &a, const PolynomialOver<T> &d, const Ring &ring)
{
	unsigned int i = a.CoefficientCount(ring);
	const int dDegree = d.Degree(ring);

	if (dDegree < 0)
		throw DivideByZero();

	r = a;
	q.m_coefficients.resize(STDMAX(0, int(i - dDegree)));

	while (i > (unsigned int)dDegree)
	{
		--i;
		q.m_coefficients[i-dDegree] = ring.Divide(r.m_coefficients[i], d.m_coefficients[dDegree]);
		for (int j=0; j<=dDegree; j++)
			ring.Reduce(r.m_coefficients[i-dDegree+j], ring.Multiply(q.m_coefficients[i-dDegree], d.m_coefficients[j]));
	}

	r.CoefficientCount(ring);	// resize r.m_coefficients
}

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

// helper function for Interpolate() and InterpolateAt()
template <class T>
void RingOfPolynomialsOver<T>::CalculateAlpha(std::vector<CoefficientType> &alpha, const CoefficientType x[], const CoefficientType y[], unsigned int n) const
{
	for (unsigned int j=0; j<n; ++j)
		alpha[j] = y[j];

	for (unsigned int k=1; k<n; ++k)
	{
		for (unsigned int j=n-1; j>=k; --j)
		{
			m_ring.Reduce(alpha[j], alpha[j-1]);

			CoefficientType d = m_ring.Subtract(x[j], x[j-k]);
			if (!m_ring.IsUnit(d))
				throw InterpolationFailed();
			alpha[j] = m_ring.Divide(alpha[j], d);
		}
	}
}

template <class T>
typename RingOfPolynomialsOver<T>::Element RingOfPolynomialsOver<T>::Interpolate(const CoefficientType x[], const CoefficientType y[], unsigned int n) const
{
	assert(n > 0);

	std::vector<CoefficientType> alpha(n);
	CalculateAlpha(alpha, x, y, n);

	std::vector<CoefficientType> coefficients((size_t)n, m_ring.Identity());
	coefficients[0] = alpha[n-1];

	for (int j=n-2; j>=0; --j)
	{
		for (unsigned int i=n-j-1; i>0; i--)
			coefficients[i] = m_ring.Subtract(coefficients[i-1], m_ring.Multiply(coefficients[i], x[j]));

		coefficients[0] = m_ring.Subtract(alpha[j], m_ring.Multiply(coefficients[0], x[j]));
	}

	return PolynomialOver<T>(coefficients.begin(), coefficients.end());
}

template <class T>
typename RingOfPolynomialsOver<T>::CoefficientType RingOfPolynomialsOver<T>::InterpolateAt(const CoefficientType &position, const CoefficientType x[], const CoefficientType y[], unsigned int n) const
{
	assert(n > 0);

	std::vector<CoefficientType> alpha(n);
	CalculateAlpha(alpha, x, y, n);

	CoefficientType result = alpha[n-1];
	for (int j=n-2; j>=0; --j)
	{
		result = m_ring.Multiply(result, m_ring.Subtract(position, x[j]));
		m_ring.Accumulate(result, alpha[j]);
	}
	return result;
}

template <class Ring, class Element>
void PrepareBulkPolynomialInterpolation(const Ring &ring, Element *w, const Element x[], unsigned int n)
{
	for (unsigned int i=0; i<n; i++)
	{
		Element t = ring.MultiplicativeIdentity();
		for (unsigned int j=0; j<n; j++)
			if (i != j)
				t = ring.Multiply(t, ring.Subtract(x[i], x[j]));
		w[i] = ring.MultiplicativeInverse(t);
	}
}

template <class Ring, class Element>
void PrepareBulkPolynomialInterpolationAt(const Ring &ring, Element *v, const Element &position, const Element x[], const Element w[], unsigned int n)
{
	assert(n > 0);

	std::vector<Element> a(2*n-1);
	unsigned int i;

	for (i=0; i<n; i++)
		a[n-1+i] = ring.Subtract(position, x[i]);

	for (i=n-1; i>1; i--)
		a[i-1] = ring.Multiply(a[2*i], a[2*i-1]);

	a[0] = ring.MultiplicativeIdentity();

	for (i=0; i<n-1; i++)
	{
		std::swap(a[2*i+1], a[2*i+2]);
		a[2*i+1] = ring.Multiply(a[i], a[2*i+1]);
		a[2*i+2] = ring.Multiply(a[i], a[2*i+2]);
	}

	for (i=0; i<n; i++)
		v[i] = ring.Multiply(a[n-1+i], w[i]);
}

template <class Ring, class Element>
Element BulkPolynomialInterpolateAt(const Ring &ring, const Element y[], const Element v[], unsigned int n)
{
	Element result = ring.Identity();
	for (unsigned int i=0; i<n; i++)
		ring.Accumulate(result, ring.Multiply(y[i], v[i]));
	return result;
}

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

template <class T, int instance>
const PolynomialOverFixedRing<T, instance> &PolynomialOverFixedRing<T, instance>::Zero()
{
	static const PolynomialOverFixedRing<T, instance> zero;
	return zero;
}

template <class T, int instance>
const PolynomialOverFixedRing<T, instance> &PolynomialOverFixedRing<T, instance>::One()
{
	static const PolynomialOverFixedRing<T, instance> one = fixedRing.MultiplicativeIdentity();
	return one;
}

NAMESPACE_END

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
免费成人小视频| 亚洲激情自拍视频| 国产精品三级视频| 图片区小说区区亚洲影院| 高清成人免费视频| 91精品视频网| 亚洲精品成人a在线观看| 国产美女在线观看一区| 欧美伦理影视网| 中文字幕一区二区三区乱码在线| 天天爽夜夜爽夜夜爽精品视频| 国产**成人网毛片九色 | 亚洲福利国产精品| av电影在线观看完整版一区二区| 欧美精品色一区二区三区| 中文字幕一区免费在线观看| 久久国产生活片100| 欧美日韩国产欧美日美国产精品| 国产精品久久久一本精品| 寂寞少妇一区二区三区| 欧美精品粉嫩高潮一区二区| 全部av―极品视觉盛宴亚洲| 色噜噜狠狠成人中文综合| 国产精品久久国产精麻豆99网站| 九一九一国产精品| 欧美一级一区二区| 青草国产精品久久久久久| 欧美视频一二三区| 伊人开心综合网| 色94色欧美sute亚洲13| 亚洲视频在线观看一区| 99久久综合狠狠综合久久| 久久久久国产精品人| 国内不卡的二区三区中文字幕 | 肉色丝袜一区二区| 欧美日韩视频不卡| 日韩精品电影一区亚洲| 欧美日韩在线免费视频| 亚洲高清视频的网址| 欧美日韩精品一区二区三区| 亚洲一二三四区不卡| 欧美午夜片在线看| 午夜久久久影院| 日韩一区二区麻豆国产| 奇米影视在线99精品| 日韩免费高清电影| 国产激情91久久精品导航| 久久久久9999亚洲精品| 成人激情av网| 一区二区三区**美女毛片| 欧美在线观看一区| 日韩精品亚洲专区| 久久综合九色综合97_久久久| 国产麻豆精品theporn| 国产精品嫩草99a| 在线视频你懂得一区| 日韩在线一区二区| 久久女同互慰一区二区三区| 成人综合婷婷国产精品久久蜜臀 | 亚洲国产色一区| 欧美一二三四在线| 成人黄色在线看| 亚洲综合在线五月| 欧美性猛交一区二区三区精品| 日韩中文字幕不卡| 日本一二三四高清不卡| 在线欧美日韩国产| 韩国精品主播一区二区在线观看 | 天堂va蜜桃一区二区三区漫画版| 欧美电影免费观看高清完整版| 国产精品一区二区果冻传媒| 亚洲欧美激情小说另类| 欧美一区二区在线免费观看| 国产成人免费在线观看不卡| 亚洲精品国产精品乱码不99| 日韩视频一区二区在线观看| 成人午夜视频在线| 日本伊人色综合网| 国产精品久久久久永久免费观看| 91精品国产91久久久久久最新毛片| 国产乱码精品1区2区3区| 亚洲午夜精品在线| 久久久天堂av| 欧美一区二区三区免费视频| 91网站在线观看视频| 久久精品国产精品亚洲红杏| 亚洲人精品午夜| 久久午夜老司机| 欧美日韩日本视频| 成人免费毛片嘿嘿连载视频| 喷水一区二区三区| 久久精品国产99国产| 亚洲精品伦理在线| 国产三级三级三级精品8ⅰ区| 欧美日韩在线播放三区四区| 欧美国产精品一区| 91麻豆精品在线观看| 亚洲免费视频中文字幕| 成人av动漫网站| 欧美国产一区视频在线观看| 国产在线播放一区| 欧美经典一区二区三区| 成人一级黄色片| 亚洲男人天堂av网| 日韩一区二区免费在线电影| 秋霞午夜鲁丝一区二区老狼| 国产人成亚洲第一网站在线播放 | 国产精品亚洲专一区二区三区| 色老综合老女人久久久| 午夜久久久影院| 欧美国产禁国产网站cc| 成人国产精品免费| 成人黄页在线观看| 97久久精品人人澡人人爽| 成人综合婷婷国产精品久久 | 国产91丝袜在线18| 国产喂奶挤奶一区二区三区| 精品欧美黑人一区二区三区| 亚洲三级在线免费| 日韩成人一区二区三区在线观看| 在线中文字幕不卡| 91麻豆精东视频| 日韩一区二区在线看| 欧美精品在线观看播放| 日韩一区二区三区电影在线观看| 欧美日韩国产精品自在自线| 在线成人免费观看| 日韩欧美一区二区不卡| 亚洲精品一区二区三区在线观看| 26uuu久久综合| 亚洲精品日日夜夜| 国产日韩精品一区二区浪潮av| 在线播放91灌醉迷j高跟美女| 欧洲在线/亚洲| 成人av一区二区三区| 天使萌一区二区三区免费观看| 国产精品第四页| 欧美va日韩va| 91免费观看国产| 国产精品一品二品| 欧美最猛性xxxxx直播| 99re6这里只有精品视频在线观看| 国产精品网曝门| 91麻豆精品国产无毒不卡在线观看| 欧美伊人精品成人久久综合97| 在线观看不卡视频| 精品欧美一区二区三区精品久久 | 国产欧美一区二区三区沐欲| 精品国精品国产尤物美女| 久久综合一区二区| 一区二区成人在线视频| 亚洲一区成人在线| 日本在线不卡一区| 国产精品一区二区在线观看网站| 韩国av一区二区三区在线观看| 国产精品一区二区三区网站| 成人精品视频一区二区三区| 99国产精品国产精品毛片| 欧美日韩久久一区二区| 日韩欧美成人激情| 国产精品热久久久久夜色精品三区 | 日韩精品一区二区在线| 久久综合色综合88| 亚洲一级二级三级在线免费观看| 性感美女久久精品| 国产麻豆视频一区| 色偷偷成人一区二区三区91| 欧美色国产精品| 中文字幕av在线一区二区三区| 亚洲欧美日韩系列| 老色鬼精品视频在线观看播放| 国产成人亚洲综合a∨婷婷| 成人av综合一区| 欧美三级中文字幕| 久久久久久久综合狠狠综合| 亚洲日本在线天堂| 午夜国产精品一区| 一本色道a无线码一区v| 日韩精品在线网站| 亚洲人成电影网站色mp4| 日本成人在线看| 欧美日韩国产不卡| 中文字幕精品在线不卡| 老司机午夜精品| 色婷婷av一区二区三区软件| 日韩限制级电影在线观看| 亚洲欧洲日韩综合一区二区| 日本不卡高清视频| 色视频欧美一区二区三区| 欧美日韩在线播放| 一区二区三区国产| 国产不卡高清在线观看视频| 欧美另类变人与禽xxxxx| 久久久亚洲国产美女国产盗摄| 久久疯狂做爰流白浆xx| 欧美性大战久久久| 国产精品久久久久影院| 亚洲美女免费视频| 欧美体内she精高潮| 一区二区三区免费看视频|