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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? polynomi.cpp

?? 300種加密解密算法(C++)源代碼,在VC下編譯通過
?? 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

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线亚洲欧美专区二区| 亚洲老妇xxxxxx| 欧美图片一区二区三区| 国产精品一区二区在线观看网站| 欧美一区二区三区爱爱| 欧美天堂一区二区三区| 欧洲精品一区二区三区在线观看| 一本大道久久精品懂色aⅴ| 高清beeg欧美| 99r精品视频| 在线免费观看日本一区| 欧美日韩在线播放三区| 欧美日韩一区二区不卡| 欧美一区二区三级| 久久久精品tv| 亚洲欧美日本韩国| 亚洲aaa精品| 久久精工是国产品牌吗| 成人午夜激情在线| 欧美无砖砖区免费| 欧美成人艳星乳罩| 国产欧美一区二区精品忘忧草 | 国产精品久久久久7777按摩| 中文字幕精品在线不卡| 亚洲精选视频在线| 亚洲成av人片一区二区三区| 免费xxxx性欧美18vr| 国内精品伊人久久久久av一坑| 粉嫩一区二区三区性色av| 色欧美片视频在线观看在线视频| 91精品国产综合久久小美女| 国产亚洲精品bt天堂精选| 亚洲精品视频在线观看网站| 日本一区中文字幕| 激情图区综合网| 一本高清dvd不卡在线观看| 日韩午夜在线观看视频| 中文字幕一区三区| 日本亚洲三级在线| 97se亚洲国产综合自在线不卡 | 狠狠色丁香九九婷婷综合五月| 成人激情免费视频| 欧美视频日韩视频| 国产嫩草影院久久久久| 日韩激情视频网站| 91亚洲精品久久久蜜桃网站| 欧美tk—视频vk| 亚洲成人动漫精品| 91一区在线观看| 国产视频不卡一区| 人妖欧美一区二区| 色诱亚洲精品久久久久久| 久久先锋影音av鲁色资源 | 欧美酷刑日本凌虐凌虐| 国产精品毛片大码女人| 精品在线一区二区| 欧美一区二区三区影视| 亚洲欧美区自拍先锋| 岛国精品在线观看| www国产精品av| 免费成人在线网站| 欧美高清视频在线高清观看mv色露露十八| 国产精品久久久一本精品 | 在线视频一区二区免费| 中文字幕一区二区三区四区| 国模套图日韩精品一区二区 | 中文幕一区二区三区久久蜜桃| 另类小说一区二区三区| 91.xcao| 最新不卡av在线| 高清不卡一二三区| 亚洲国产精品二十页| 韩日精品视频一区| 精品国产区一区| 国产一区二区三区综合| 欧美精品一区二区三区高清aⅴ| 麻豆精品在线视频| 777欧美精品| 七七婷婷婷婷精品国产| 日韩精品一区二区三区老鸭窝 | 香蕉加勒比综合久久| 在线精品国精品国产尤物884a| 亚洲乱码国产乱码精品精小说 | 久久久另类综合| 国产一区二区主播在线| 久久久久久久久久久黄色| 成人午夜免费视频| 一区二区三区四区中文字幕| 欧美三级日韩三级国产三级| 亚洲成av人片www| 欧美成人bangbros| 国产不卡免费视频| 一区二区在线观看视频| 欧美三级乱人伦电影| 免费高清在线一区| 日本一区二区三区免费乱视频| 成人动漫视频在线| 亚洲第一福利一区| 欧美xxxxxxxx| av电影在线观看完整版一区二区| 亚洲图片欧美色图| 欧美r级在线观看| av一区二区三区在线| 亚洲成年人网站在线观看| 精品国产网站在线观看| 粉嫩aⅴ一区二区三区四区 | 综合色天天鬼久久鬼色| 欧美一区二区播放| 国产91在线观看| 亚洲综合清纯丝袜自拍| 欧美大片免费久久精品三p| 色综合久久久久久久久| 丝袜亚洲另类丝袜在线| 欧美国产一区二区在线观看| 欧美色涩在线第一页| 国产盗摄女厕一区二区三区| 亚洲成av人片在线| 久久精品夜色噜噜亚洲aⅴ| 色婷婷激情一区二区三区| 国内精品伊人久久久久av影院| 一区二区三区欧美激情| 久久久精品免费网站| 欧美视频中文字幕| 成人免费av资源| 免费人成精品欧美精品| 国产精品久久网站| 久久综合99re88久久爱| 欧美日韩国产精品成人| 99re成人精品视频| 精品一二三四区| 三级亚洲高清视频| 洋洋成人永久网站入口| 国产精品久久久久三级| 久久影院午夜片一区| 欧美一级艳片视频免费观看| 欧美色图第一页| 91精品办公室少妇高潮对白| 国产精品一区不卡| 国模冰冰炮一区二区| 久久国产精品色婷婷| 另类小说欧美激情| 毛片av一区二区三区| 亚洲精选视频免费看| 亚洲色图在线视频| 18成人在线视频| 一区在线观看免费| 中文字幕亚洲在| 久久综合九色综合97婷婷女人| 欧美xxxxx裸体时装秀| 欧美草草影院在线视频| 精品精品国产高清a毛片牛牛| 欧美精品一区二区三区很污很色的| 在线成人午夜影院| 8x8x8国产精品| 日韩一区二区中文字幕| 制服丝袜亚洲精品中文字幕| 7777精品伊人久久久大香线蕉最新版 | 欧美国产精品中文字幕| 久久综合九色综合久久久精品综合 | 久久久久国产精品人| 2020国产精品久久精品美国| 精品免费一区二区三区| 欧美videos中文字幕| 精品国产伦一区二区三区免费| 日韩欧美一级二级| 久久久久国产精品麻豆| 国产欧美一区二区精品久导航| 国产三级三级三级精品8ⅰ区| 国产精品麻豆久久久| 亚洲免费电影在线| 午夜精品久久久久影视| 日韩在线a电影| 精品一区二区三区在线观看 | 日韩精品免费专区| 国产做a爰片久久毛片| 国产白丝网站精品污在线入口| av电影天堂一区二区在线观看| 欧美午夜精品免费| 日韩欧美一区二区久久婷婷| 香港成人在线视频| 国产欧美日韩麻豆91| 亚洲免费观看在线观看| 日韩经典一区二区| 国产成人免费视| 91成人国产精品| 精品国产制服丝袜高跟| 亚洲欧美影音先锋| 男男视频亚洲欧美| 成人高清免费观看| 欧美日韩成人综合| 精品在线免费视频| 成人三级伦理片| 欧美一区三区二区| 一区在线观看视频| 精品一区二区免费视频| 91成人在线精品| 国产色综合一区| 蜜臀av一区二区在线免费观看 | 99视频精品全部免费在线| 51精品视频一区二区三区|