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

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

?? polynomi.cpp

?? 300個加解密的集合程序
?? 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 <iostream>
#include <strstream>
#include <vector>

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.One();
		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.Zero()))
		count--;
	const_cast<std::vector<CoefficientType> &>(m_coefficients).resize(count);
	return count;
}

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

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.Zero());

	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.Zero());

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

	return *this;
}

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

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

	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.Zero());
	while (i > n)
	{
		i--;
		m_coefficients[i] = m_coefficients[i-n];
	}
	while (i)
	{
		i--;
		m_coefficients[i] = ring.Zero();
	}
	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.Zero());
	}
	else
		m_coefficients.resize(0, ring.Zero());
	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.Zero());
	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.Zero();
}

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.Zero())
			{
				if (firstTerm)
				{
					firstTerm = false;
					if (!i || !ring.Equal(m_coefficients[i], ring.One()))
						out << m_coefficients[i];
				}
				else
				{
					CoefficientType inverse = ring.Inverse(m_coefficients[i]);
					ostrstream pstr, nstr;

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

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

				switch (i)
				{
				case 0:
					break;
				case 1:
					out << "x";
					break;
				default:
					out << "x^" << i;
				}
			}
		}
	}
	else
	{
		out << ring.Zero();
	}
	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>
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.Zero());
	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>
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 T, int instance>
const T PolynomialOverFixedRing<T, instance>::fixedRing;

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.One();
	return one;
}

NAMESPACE_END

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品国模大尺度视频| 韩国精品一区二区| 奇米综合一区二区三区精品视频| 狠狠v欧美v日韩v亚洲ⅴ| 91啪亚洲精品| 久久综合九色综合97_久久久| 日韩理论在线观看| 国产在线精品一区在线观看麻豆| 在线精品视频小说1| 国产色婷婷亚洲99精品小说| 五月婷婷综合在线| 色国产综合视频| 国产欧美一区二区精品秋霞影院 | 舔着乳尖日韩一区| 成人av网址在线| 久久久99免费| 日本成人在线看| 欧美另类z0zxhd电影| 一区二区三区四区五区视频在线观看| 国产精品亚洲第一| 精品国产乱码久久久久久影片| 香蕉久久一区二区不卡无毒影院| 99r精品视频| 国产精品福利一区| 成人av电影在线播放| 国产欧美一区二区在线观看| 精品一区二区三区影院在线午夜| 欧美日韩国产区一| 午夜在线电影亚洲一区| 欧洲人成人精品| 亚洲综合视频在线| 欧美日韩一区在线| 午夜久久久久久电影| 欧美日韩国产首页| 日本麻豆一区二区三区视频| 91.com在线观看| 美女精品一区二区| 精品成a人在线观看| 国产一区激情在线| 欧美激情一区二区在线| 成人午夜av影视| 亚洲欧洲美洲综合色网| 91农村精品一区二区在线| 亚洲三级电影全部在线观看高清| 成人免费视频免费观看| 亚洲欧美激情插 | 欧美视频在线不卡| 亚洲午夜久久久久久久久久久 | 国产日韩欧美制服另类| 大白屁股一区二区视频| 亚洲精品免费在线观看| 欧美日韩日日摸| 蜜桃久久av一区| 国产日韩精品一区二区浪潮av| 成人免费av网站| 亚洲精品欧美二区三区中文字幕| 欧美体内she精视频| 蜜桃免费网站一区二区三区 | 欧美疯狂做受xxxx富婆| 久久电影网电视剧免费观看| 久久久亚洲午夜电影| 99久久精品费精品国产一区二区| 亚洲一区二区精品3399| 精品国产99国产精品| 波多野结衣亚洲| 日本中文字幕一区二区有限公司| 日韩精品一区二区三区视频| 风间由美性色一区二区三区| 一区二区在线观看免费视频播放| 欧美日韩国产一级二级| 国产精品系列在线观看| 亚洲制服丝袜一区| 日韩精品一区二区三区在线| 成人av网址在线观看| 日本系列欧美系列| 中文字幕一区不卡| 日韩一级免费观看| 色婷婷激情一区二区三区| 经典三级一区二区| 亚洲大片在线观看| 欧美极品少妇xxxxⅹ高跟鞋| 欧美日韩国产乱码电影| av一二三不卡影片| 国产最新精品免费| 日韩精品三区四区| 最好看的中文字幕久久| 精品国产乱码久久久久久老虎 | 欧美日韩国产一二三| 成人免费高清视频在线观看| 卡一卡二国产精品| 亚洲精品国产无套在线观 | 欧美亚洲国产一区二区三区va| 国产精品白丝jk白祙喷水网站| 亚洲一二三区视频在线观看| 国产精品青草久久| 国产亚洲短视频| 欧美一级片免费看| 欧美三级中文字| 日本久久精品电影| 99精品欧美一区| 成人黄色在线看| 国产成人免费视频网站| 韩国欧美一区二区| 麻豆精品一二三| 日本不卡一区二区| 午夜精品成人在线视频| 午夜国产精品一区| 亚洲bt欧美bt精品| 亚洲福利视频导航| 亚洲福中文字幕伊人影院| 亚洲资源中文字幕| 亚洲影院理伦片| 亚洲成a人v欧美综合天堂下载| 一区二区三区在线影院| 一区二区三区日本| 亚洲综合另类小说| 五月天亚洲精品| 日韩高清电影一区| 麻豆一区二区三区| 精品亚洲免费视频| 国产精品一卡二卡| 成人免费高清视频| 一本色道**综合亚洲精品蜜桃冫| av网站免费线看精品| 色综合久久66| 欧美精品日韩精品| 欧美一区二区三区电影| 欧美videos大乳护士334| 久久久国际精品| ㊣最新国产の精品bt伙计久久| 国产精品久久夜| 亚洲精品国产精华液| 天天av天天翘天天综合网色鬼国产| 婷婷综合在线观看| 精品一区二区三区在线观看国产 | a4yy欧美一区二区三区| 日本久久精品电影| 51午夜精品国产| 国产婷婷色一区二区三区| 亚洲女同一区二区| 午夜天堂影视香蕉久久| 精品一区二区三区久久久| 懂色中文一区二区在线播放| 91福利精品第一导航| 欧美日韩成人综合天天影院 | 国产清纯白嫩初高生在线观看91| 国产精品高潮久久久久无| 亚洲一区在线免费观看| 麻豆91免费看| 99久久久国产精品| 欧美一区二区女人| 中文字幕在线不卡一区二区三区| 亚洲一卡二卡三卡四卡五卡| 精品在线你懂的| 欧美曰成人黄网| 26uuu久久综合| 洋洋成人永久网站入口| 九九九久久久精品| 欧亚洲嫩模精品一区三区| 精品国产一二三区| 亚洲丰满少妇videoshd| 国产成人欧美日韩在线电影 | jlzzjlzz国产精品久久| 91精品婷婷国产综合久久性色| 国产欧美精品一区二区色综合 | 91论坛在线播放| 日韩免费一区二区三区在线播放| 亚洲丝袜美腿综合| 国产精品一级黄| 欧美高清你懂得| 17c精品麻豆一区二区免费| 国模冰冰炮一区二区| 欧美日韩成人高清| 亚洲欧美视频在线观看| 国产成人免费视频网站高清观看视频| 欧美老女人第四色| 亚洲精品成人少妇| 波多野结衣的一区二区三区| 精品人伦一区二区色婷婷| 亚洲夂夂婷婷色拍ww47| 北条麻妃一区二区三区| 国产日韩欧美综合在线| 国产一区二区三区高清播放| 91精品国产免费| 偷拍日韩校园综合在线| 欧美亚洲免费在线一区| 亚洲人成伊人成综合网小说| 成人性生交大片免费看在线播放 | 国产精品视频看| 国产在线精品一区二区| 制服丝袜亚洲播放| 无吗不卡中文字幕| 欧美精品成人一区二区三区四区| ...中文天堂在线一区| 99久久精品国产网站| 亚洲人xxxx| 在线观看不卡视频| 亚洲一区二区精品视频| 欧美猛男男办公室激情| 亚洲成av人片一区二区梦乃 |