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

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

?? uvlong.cpp

?? 橢圓曲線密碼C實現的
?? CPP
字號:
#include "stdafx.h"
#include "uvlong.h"

//-------------------------------------------------------------------------------
void shl_cl(ULINT  x)
{
	ushort carry = 0;
	ushort N = x[0]; // necessary, since n can change
	
	for (int i = 1; i <= N+1; i+=1 )
	{
		ushort u = x[i];
		x[i] = ((u<<1)+carry);
		carry = u>>(BPU-1);
		if(x[i] != 0 )
		{
			x[0] = i;
		}
	}
	trim(x);
	
}

void shr_cl(ULINT  x)
{
	ushort carry = 0;
	ushort i=x[0];
	while (i>0)
	{	
		ushort u = x[i];
		x[i] = ((u>>1)+carry);
		carry = u<<(BPU-1);
		i -= 1;
	}
}

void clean_cl(ULINT  x)	
{ 
	for(int i = 0; i< CLINTMAXDIGIT+1; i++) x[i] = 0; 
}

void init_cl(ULINT  x,ushort v)
{
	clean_cl(x);
	if(x > 0)
	{
		x[0] = 1;
		x[1] = v;
	}
}

int copy_cl(ULINT   a, ULINT const b)
{
	clean_cl(a);
	if(b[0] > CLINTMAXDIGIT)
		return RSA_ERR_OF;
	
	for(int i = 0; i<= b[0]; i++)
	{
		a[i] = b[i] ;
	}
	
	return RSA_ERR_OK;
}

int add_cl(ULINT  const a,ULINT  const b,ULINT s)
{

	ushort	c = 0;
	ushort	const *ap,*bp;
	
	unsigned int	i = 1;
	unsigned int	t;
	unsigned int	B = (1<<(8*sizeof(ushort)));	//B為基數(一個unsigned short),
	
	ULINT	tmp;
	clean_cl(tmp);
	
	if( comp_cl(a,b) >= 0 )
	{
		ap = a;
		bp = b;
		SET_CLINTSIZE(tmp,a[0]);
	}else{
		ap = b;
		bp = a;
		SET_CLINTSIZE(tmp,b[0]);
	}
	
	do{ 
		t =  ap[i] + bp[i] + c;
		tmp[i] =  t&(B-1);
		c =  t/B;
		if(tmp[i] != 0 )
		{
			tmp[0] = i;
		}
	}while( ++i <= bp[0] );
	
	do{
		t = ap[i] + c;
		tmp[i] = t&(B-1);
		c = t/B;
		if(tmp[i] != 0 )
		{
			tmp[0] = i;
		}
	}while( ++i <= ap[0] );
	
	if(i > CLINTMAXDIGIT)
		return RSA_ERR_OF;
	tmp[i] = c;	
	if(tmp[i] != 0 )
	{
		tmp[0] = i;
	}
	copy_cl(s,tmp);
	return RSA_ERR_OK;
}

int sub_cl(ULINT const a,ULINT  const b,ULINT s)
{
	
	ushort	c = 1;
	ushort	const *ap,*bp;
	
	unsigned int	i = 1;
	unsigned int	t;
	unsigned int	B = (1<<(8*sizeof(ushort)));	//B為基數(一個unsigned short),
	
	ULINT	tmp;
	clean_cl(tmp);
	if( comp_cl(a,b) >= 0 )
	{
		ap = a;
		bp = b;
		SET_CLINTSIZE(tmp,a[0]);
	}else{
		ap = b;
		bp = a;
		SET_CLINTSIZE(tmp,b[0]);
	}
	
	do{
		if(c==1)
			t =  B + ap[i] - bp[i] ;
		else
			t =  B - 1 + ap[i] - bp[i] ;
		
		tmp[i] =  t & (B-1);
		c =  t/B;
		if(tmp[i] != 0)
		{
			tmp[0] = i;
		}
		
	}while( ++i <= bp[0]);
	
	do{
		if(c==1)
			t =  B + ap[i];
		else
			t =  B - 1 + ap[i];
		
		tmp[i] = (t&(B-1));
		c = t/B;		
		if(tmp[i]  != 0)
		{
			tmp[0] = i;
		}
	}while(++i <= ap[0]);		
	
	copy_cl(s,tmp);
	return RSA_ERR_OK;
}

int comp_cl( ULINT const a,ULINT  const b)
{	
	if(a[0]>CLINTMAXDIGIT || b[0]>CLINTMAXDIGIT)
		return 0;	//不作處理

	int i = a[0];
	if( i < b[0])	i = b[0];

	while(i > 0){
		if ( a[i] > b[i] ) return +1;
		if ( a[i] < b[i] ) return -1;
		i--;
	};
	
	return 0;
}

int	trim( ULINT  a)
{
	int i;
	i = a[0];
	if(i>CLINTMAXDIGIT)
		return RSA_ERR_02;
	while(i> 0 && a[i]== 0){i--;}
	a[0] = i;
	
	return RSA_ERR_OK;	
}

int mul_cl( ULINT const a, ULINT  const b, ULINT mul, int keep)
{
	//  fast_mul( x, y, x.bits()+y.bits() );
	// *this = (x*y) % (2**keep)
	ULINT  pt;
	int i,limit = (keep+BPU-1)/BPU; // size of result in ushort
	clean_cl(pt);
	
	int	min = a[0]; if ( min > limit ) min = limit;
	
	for (i = 1; i <= min; i += 1)
	{
		ushort m = a[i];
		ushort c = 0; // carry
		int min = i+b[0]; if (min>limit) min = limit;
		for ( int j = i; j <= min; j+=1 )
		{
			// This is the critical loop
			// Machine dependent code could help here
			// c:a[j] = a[j] + c + m*y.a[j-i];
			ushort w, v = pt[j], p = b[j-i+1];
			v += c; c = ( v < c );
			w = ushort(lo(p)*lo(m)); v += w; c += ( v < w );
			w = ushort(lo(p)*hi(m)); c += hi(w); w = lh(w); v += w; c += ( v < w );
			w = ushort(hi(p)*lo(m)); c += hi(w); w = lh(w); v += w; c += ( v < w );
			c += hi(p) * hi(m);
			pt[j] = v;
		}
		
		while ( c && j<=limit )
		{
			pt[j] += c;
			c = pt[j] < c;
			j += 1;
		}
	}
	// eliminate unwanted bits
	keep %= BPU; if (keep) pt[limit] &= (1<<keep)-1;
	// calculate n
	while (limit && pt[limit] ==0 ) limit-=1;
	pt[0] = limit;
	copy_cl(mul,pt);
	return RSA_ERR_OK;

}

int div_cl( ULINT const a, ULINT  const b, ULINT div ,	ULINT  rem)
{
	ULINT s,r,d,m;	
	copy_cl(r,a);
	copy_cl(m,b);
	init_cl(s,1);
	clean_cl(d);
	
	trim(r);	
	trim(m);	
	
	if(IsZero(m))
		return RSA_ERR_02;

	while ( comp_cl(r,m) > 0 )
	{
		shl_cl(m);
		shl_cl(s);
	}
	
	while ( comp_cl(r,b) >= 0 )
	{	
		while ( comp_cl(r,m) < 0 )
		{
			shr_cl(m);
			shr_cl(s);
		}
		sub_cl(r, m ,r);
		add_cl(d, s ,d);	
	}
	copy_cl(div,d);
	copy_cl(rem,r);
	return RSA_ERR_OK;
}

int  modexp_cl( const ULINT x, const ULINT e,const ULINT mod,ULINT result)
{

	int  j=0,i = e[0]*BPU;
	if(i == 0)
		return RSA_ERR_02;
	
	while ( i && ((e[((i-1)/BPU)+1] & (1<<(i-1)%BPU)) == 0) ) 
		i -= 1;	
	
	unsigned char *c=new unsigned char[i];
	memset(c,0x00,i);
	while ( j<i )
	{
		if((e[(j/BPU)+1] & (1<<j%BPU)) > 0)
		{
			c[j] = 1;
		}else{
			c[j] = 0;
		}
		j ++;
	}
	
	ULINT	z;
	init_cl(z,1);
	
	ULINT	div;
	for( j = i-1;j >= 0;j--)
	{
		mul_cl(z,z,z,2*z[0]*16);
		div_cl(z,mod,div,z);
		if(c[j]>0)
		{
			mul_cl(z,x,z,(z[0]+x[0])*16);
			div_cl(z,mod,div,z);
		}
	}
	delete []c;
	copy_cl(result,z);
	return RSA_ERR_OK;
}

int  gcd_cl( const ULINT  X, const ULINT  Y ,ULINT result)
{
	ULINT x, y;
	copy_cl(x,X);
	copy_cl(y,Y);
	
	ULINT t,div;
	init_cl(t,0);
	while (1)
	{
		if(comp_cl(y,t) == 0)
		{
			copy_cl(result,x);
			break; 
		}
		div_cl(x,y,div,x);
		
		if(comp_cl(x,t) == 0)
		{
			copy_cl(result,y);
			break; 
		}
		div_cl(y,x,div,y);
	}
	trim(result);
	return RSA_ERR_OK;
}

int IsZero(const ULINT a)
{
	int i = a[0];
	while(i>0)
	{
		if(a[i]>0 )
			return 0;
		i--;
	}
	return 1;
}
//------------------------------------------------------------------------

uvlong::uvlong()
{
	m_share = 0;
	clean_cl(m_clint);	
}

uvlong::uvlong ( unsigned int	x )
{
	m_share = 0;
	int y = x;
	if(y<0){ x = (y^0xffffffff)+1; }
	
	clean_cl(m_clint);
	for(int i = 1;i<=2;i++)
	{
		m_clint[i] = (x>>(BPU*(i-1))) & 0x0ffff;
		if(m_clint[i]>0)
			m_clint[0] = i;
	}
	
}

uvlong::~uvlong()
{

}

uvlong::operator unsigned()
{
	int x= ( m_clint[0] > 2) ? 2 : m_clint[0];
	
	unsigned int n=0;
	for(int i = 1 ; i <= x ; i++ )
	{
		n += (m_clint[i]<<(BPU*(i-1)));
	}
	return n;
}

uvlong& uvlong::Append( const ushort& x )
{
	if( m_clint[0] < CLINTMAXDIGIT )
	{			
		m_clint[0]	+=	1;
		m_clint[m_clint[0]]	=	x;
	}
	
	return *this;
}

int uvlong::GetBits() const
{
	int x = m_clint[0]*BPU;
	while (x && test(x-1)==0) x -= 1;
	return x;
	
}

int uvlong::test(unsigned int i) const
{
	return (m_clint[(i/BPU)+1] & (1<<(i%BPU)) ) != 0; 
}

uvlong& uvlong::modexp( const uvlong & m, const uvlong & e, const uvlong & mod )
{
	modexp_cl(m.m_clint, e.m_clint, mod.m_clint, m_clint);
	return *this;
}

void uvlong::ReArray()
{
	unsigned j=0, i = m_clint[0];
	unsigned char * p ;
	
	while(m_clint[i] == 0 && i >= 1){
		i--;
	}
	if(i > 0)
	{
		p =  (unsigned char *)&m_clint[i];
		if(m_clint[i] > 0xff){ p++; }
		while(j<8)
		{
			if(*p & (1<<j)){ break; }
			j++;
		}
		*p = (*p)>>j;	
	}	
	m_clint[0] = i;
}

uvlong& uvlong::gcd(const uvlong &a, const uvlong &b)
{
	gcd_cl(a.m_clint, b.m_clint, m_clint);
	return *this;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产欧美一区二区成人| 精品一区二区在线免费观看| 播五月开心婷婷综合| 久久精品视频在线看| 国产精品99久久不卡二区| 精品国产sm最大网站免费看| 国产精品一区二区久久不卡| 欧美国产一区视频在线观看| 色综合咪咪久久| 午夜成人免费电影| 精品久久99ma| www.综合网.com| 亚洲成人动漫精品| 亚洲成a人v欧美综合天堂| 欧美色精品在线视频| 久久91精品国产91久久小草| 欧美国产精品专区| 在线亚洲人成电影网站色www| 天堂午夜影视日韩欧美一区二区| 欧美成人精品福利| 99久久综合国产精品| 亚洲成人av在线电影| 亚洲精品一区二区三区影院| av一区二区三区黑人| 天天色天天操综合| 日本一区二区三级电影在线观看| 一本色道久久综合狠狠躁的推荐| 丝袜亚洲精品中文字幕一区| 久久久久9999亚洲精品| 欧美最新大片在线看| 精品一区二区三区免费毛片爱| 国产精品免费aⅴ片在线观看| 欧美视频精品在线观看| 国产精品一区三区| 亚洲一区二区三区小说| 精品国产免费视频| 在线精品视频小说1| 国产一区在线观看麻豆| 亚洲国产精品视频| 国产欧美日韩另类视频免费观看| 91国偷自产一区二区三区成为亚洲经典| 日本欧美一区二区三区乱码| 国产精品福利影院| 精品国产乱码久久久久久闺蜜| 99在线视频精品| 狠狠网亚洲精品| 偷拍与自拍一区| 亚洲激情五月婷婷| 国产午夜精品久久久久久久| 日韩一区二区麻豆国产| 在线免费亚洲电影| 9l国产精品久久久久麻豆| 激情都市一区二区| 日本免费新一区视频| 夜夜嗨av一区二区三区网页 | 蜜臀av性久久久久av蜜臀妖精| 中文字幕一区二区在线观看| 久久婷婷综合激情| 日韩一区二区视频| 欧美日本在线播放| 91精品办公室少妇高潮对白| 成人av在线一区二区三区| 国产一区三区三区| 狠狠色丁香久久婷婷综合_中| 日韩精品成人一区二区在线| 91丨porny丨中文| 国产毛片精品视频| 国产自产视频一区二区三区| 美女视频第一区二区三区免费观看网站| 亚洲黄网站在线观看| 中文字幕在线播放不卡一区| 欧美韩国日本一区| 国产欧美1区2区3区| 国产三级一区二区三区| 国产亚洲综合在线| 中文字幕欧美日韩一区| 国产欧美日韩综合| 国产精品久久久一本精品| 欧美激情在线一区二区| 欧美国产一区视频在线观看| 国产精品无圣光一区二区| 欧美国产综合一区二区| 国产精品久久久久影院亚瑟 | 粉嫩蜜臀av国产精品网站| 国产精品一二三四五| 国产一级精品在线| 成人午夜视频在线| 99麻豆久久久国产精品免费优播| 99精品国产99久久久久久白柏| av成人动漫在线观看| 91视频一区二区三区| 日本道精品一区二区三区| 欧美体内she精视频| 欧美二区三区91| 欧美mv和日韩mv国产网站| 久久先锋影音av| 国产精品久久一级| 亚洲国产精品一区二区www在线| 亚洲成人综合网站| 另类成人小视频在线| 国产一区二区三区精品视频| 成人一区二区三区中文字幕| 91蜜桃在线免费视频| 3d成人动漫网站| 精品成a人在线观看| 中文字幕一区二区三区四区不卡 | 亚洲一区二区精品久久av| 亚洲成a人片在线不卡一二三区| 麻豆成人免费电影| 不卡的电影网站| 9191久久久久久久久久久| 久久综合九色综合久久久精品综合| 国产日韩成人精品| 亚洲国产精品久久不卡毛片| 国产自产v一区二区三区c| 91在线视频播放| 欧美日韩国产中文| 国产午夜精品福利| 亚洲一区欧美一区| 国产xxx精品视频大全| 欧美三片在线视频观看| 国产日韩欧美电影| 五月婷婷激情综合| www.久久精品| 欧美成人一区二区三区在线观看| 国产精品久久久久一区| 蜜臀精品久久久久久蜜臀| 91丝袜国产在线播放| 精品乱人伦小说| 一区二区三区精品视频| 国产真实乱偷精品视频免| 欧洲精品一区二区三区在线观看| 精品久久一区二区| 亚洲成人综合网站| 本田岬高潮一区二区三区| 日韩小视频在线观看专区| 亚洲精品成人悠悠色影视| 国产精品一二三四区| 欧美一区二区三区视频免费 | 久久精品视频免费| 日韩精品成人一区二区在线| 色综合天天综合网天天狠天天| 久久综合狠狠综合久久综合88| 偷拍一区二区三区四区| 91论坛在线播放| 国产精品网站在线播放| 国产一区二区中文字幕| 91精品国产日韩91久久久久久| 亚洲黄色性网站| 99久久99久久久精品齐齐| 国产日韩欧美a| 国产在线播放一区| 欧美大片顶级少妇| 日本欧美肥老太交大片| 欧美日韩亚洲综合| 亚洲综合激情小说| 一本久久综合亚洲鲁鲁五月天 | 99精品视频中文字幕| 精品对白一区国产伦| 麻豆成人91精品二区三区| 91麻豆精品国产91久久久更新时间| 亚洲精品v日韩精品| 日本韩国一区二区三区视频| 最新高清无码专区| aaa亚洲精品| 亚洲精品国久久99热| 日本道免费精品一区二区三区| 日韩精品一区第一页| 在线成人免费视频| 中文字幕精品综合| 成人av动漫在线| 国产精品久久三区| 91麻豆免费观看| 亚洲精品国产a久久久久久| 欧洲一区二区三区在线| 一区二区三区.www| 欧美日韩一本到| 老司机免费视频一区二区| 精品久久人人做人人爽| 国内国产精品久久| 欧美国产激情二区三区 | 亚洲国产精品天堂| 9191精品国产综合久久久久久| 蜜臀av一区二区三区| 日韩欧美的一区二区| 国产又粗又猛又爽又黄91精品| 欧美mv和日韩mv的网站| 成人一级片网址| 一区二区三区日韩| 欧美一区二区视频在线观看2020| 久久精品av麻豆的观看方式| 国产日本欧美一区二区| 色婷婷综合久久久久中文| 午夜视频在线观看一区二区三区| 日韩午夜在线影院| 成人小视频在线观看| 一区二区在线观看视频| 欧美日产国产精品| 国产高清久久久| 亚洲激情校园春色|