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

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

?? biginteger.cs

?? JAVA實現的RSA公鑰加密方法
?? CS
?? 第 1 頁 / 共 5 頁
字號:
		//
		//***********************************************************************

		public int bitCount()
		{
			while(dataLength > 1 && data[dataLength-1] == 0)
				dataLength--;

			uint value = data[dataLength - 1];
			uint mask = 0x80000000;
			int bits = 32;

			while(bits > 0 && (value & mask) == 0)
			{
				bits--;
				mask >>= 1;
			}
			bits += ((dataLength - 1) << 5);

			return bits;
		}


		//***********************************************************************
		// Probabilistic prime test based on Fermat's little theorem
		//
		// for any a < p (p does not divide a) if
		//      a^(p-1) mod p != 1 then p is not prime.
		//
		// Otherwise, p is probably prime (pseudoprime to the chosen base).
		//
		// Returns
		// -------
		// True if "this" is a pseudoprime to randomly chosen
		// bases.  The number of chosen bases is given by the "confidence"
		// parameter.
		//
		// False if "this" is definitely NOT prime.
		//
		// Note - this method is fast but fails for Carmichael numbers except
		// when the randomly chosen base is a factor of the number.
		//
		//***********************************************************************

		public bool FermatLittleTest(int confidence)
		{
			BigInteger thisVal;
			if((this.data[maxLength-1] & 0x80000000) != 0)        // negative
				thisVal = -this;
			else
				thisVal = this;

			if(thisVal.dataLength == 1)
			{
				// test small numbers
				if(thisVal.data[0] == 0 || thisVal.data[0] == 1)
					return false;
				else if(thisVal.data[0] == 2 || thisVal.data[0] == 3)
					return true;
			}

			if((thisVal.data[0] & 0x1) == 0)     // even numbers
				return false;

			int bits = thisVal.bitCount();
			BigInteger a = new BigInteger();
			BigInteger p_sub1 = thisVal - (new BigInteger(1));
			Random rand = new Random();

			for(int round = 0; round < confidence; round++)
			{
				bool done = false;

				while(!done)		// generate a < n
				{
					int testBits = 0;

					// make sure "a" has at least 2 bits
					while(testBits < 2)
						testBits = (int)(rand.NextDouble() * bits);

					a.genRandomBits(testBits, rand);

					int byteLen = a.dataLength;

					// make sure "a" is not 0
					if(byteLen > 1 || (byteLen == 1 && a.data[0] != 1))
						done = true;
				}

				// check whether a factor exists (fix for version 1.03)
				BigInteger gcdTest = a.gcd(thisVal);
				if(gcdTest.dataLength == 1 && gcdTest.data[0] != 1)
					return false;

				// calculate a^(p-1) mod p
				BigInteger expResult = a.modPow(p_sub1, thisVal);

				int resultLen = expResult.dataLength;

				// is NOT prime is a^(p-1) mod p != 1

				if(resultLen > 1 || (resultLen == 1 && expResult.data[0] != 1))
				{
					//Console.WriteLine("a = " + a.ToString());
					return false;
				}
			}

			return true;
		}


		//***********************************************************************
		// Probabilistic prime test based on Rabin-Miller's
		//
		// for any p > 0 with p - 1 = 2^s * t
		//
		// p is probably prime (strong pseudoprime) if for any a < p,
		// 1) a^t mod p = 1 or
		// 2) a^((2^j)*t) mod p = p-1 for some 0 <= j <= s-1
		//
		// Otherwise, p is composite.
		//
		// Returns
		// -------
		// True if "this" is a strong pseudoprime to randomly chosen
		// bases.  The number of chosen bases is given by the "confidence"
		// parameter.
		//
		// False if "this" is definitely NOT prime.
		//
		//***********************************************************************

		public bool RabinMillerTest(int confidence)
		{
			BigInteger thisVal;
			if((this.data[maxLength-1] & 0x80000000) != 0)        // negative
				thisVal = -this;
			else
				thisVal = this;

			if(thisVal.dataLength == 1)
			{
				// test small numbers
				if(thisVal.data[0] == 0 || thisVal.data[0] == 1)
					return false;
				else if(thisVal.data[0] == 2 || thisVal.data[0] == 3)
					return true;
			}

			if((thisVal.data[0] & 0x1) == 0)     // even numbers
				return false;


			// calculate values of s and t
			BigInteger p_sub1 = thisVal - (new BigInteger(1));
			int s = 0;

			for(int index = 0; index < p_sub1.dataLength; index++)
			{
				uint mask = 0x01;

				for(int i = 0; i < 32; i++)
				{
					if((p_sub1.data[index] & mask) != 0)
					{
						index = p_sub1.dataLength;      // to break the outer loop
						break;
					}
					mask <<= 1;
					s++;
				}
			}

			BigInteger t = p_sub1 >> s;

			int bits = thisVal.bitCount();
			BigInteger a = new BigInteger();
			Random rand = new Random();

			for(int round = 0; round < confidence; round++)
			{
				bool done = false;

				while(!done)		// generate a < n
				{
					int testBits = 0;

					// make sure "a" has at least 2 bits
					while(testBits < 2)
						testBits = (int)(rand.NextDouble() * bits);

					a.genRandomBits(testBits, rand);

					int byteLen = a.dataLength;

					// make sure "a" is not 0
					if(byteLen > 1 || (byteLen == 1 && a.data[0] != 1))
						done = true;
				}

				// check whether a factor exists (fix for version 1.03)
				BigInteger gcdTest = a.gcd(thisVal);
				if(gcdTest.dataLength == 1 && gcdTest.data[0] != 1)
					return false;

				BigInteger b = a.modPow(t, thisVal);

				/*
						Console.WriteLine("a = " + a.ToString(10));
						Console.WriteLine("b = " + b.ToString(10));
						Console.WriteLine("t = " + t.ToString(10));
						Console.WriteLine("s = " + s);
						*/

				bool result = false;

				if(b.dataLength == 1 && b.data[0] == 1)         // a^t mod p = 1
					result = true;

				for(int j = 0; result == false && j < s; j++)
				{
					if(b == p_sub1)         // a^((2^j)*t) mod p = p-1 for some 0 <= j <= s-1
					{
						result = true;
						break;
					}

					b = (b * b) % thisVal;
				}

				if(result == false)
					return false;
			}
			return true;
		}


		//***********************************************************************
		// Probabilistic prime test based on Solovay-Strassen (Euler Criterion)
		//
		// p is probably prime if for any a < p (a is not multiple of p),
		// a^((p-1)/2) mod p = J(a, p)
		//
		// where J is the Jacobi symbol.
		//
		// Otherwise, p is composite.
		//
		// Returns
		// -------
		// True if "this" is a Euler pseudoprime to randomly chosen
		// bases.  The number of chosen bases is given by the "confidence"
		// parameter.
		//
		// False if "this" is definitely NOT prime.
		//
		//***********************************************************************

		public bool SolovayStrassenTest(int confidence)
		{
			BigInteger thisVal;
			if((this.data[maxLength-1] & 0x80000000) != 0)        // negative
				thisVal = -this;
			else
				thisVal = this;

			if(thisVal.dataLength == 1)
			{
				// test small numbers
				if(thisVal.data[0] == 0 || thisVal.data[0] == 1)
					return false;
				else if(thisVal.data[0] == 2 || thisVal.data[0] == 3)
					return true;
			}

			if((thisVal.data[0] & 0x1) == 0)     // even numbers
				return false;


			int bits = thisVal.bitCount();
			BigInteger a = new BigInteger();
			BigInteger p_sub1 = thisVal - 1;
			BigInteger p_sub1_shift = p_sub1 >> 1;

			Random rand = new Random();

			for(int round = 0; round < confidence; round++)
			{
				bool done = false;

				while(!done)		// generate a < n
				{
					int testBits = 0;

					// make sure "a" has at least 2 bits
					while(testBits < 2)
						testBits = (int)(rand.NextDouble() * bits);

					a.genRandomBits(testBits, rand);

					int byteLen = a.dataLength;

					// make sure "a" is not 0
					if(byteLen > 1 || (byteLen == 1 && a.data[0] != 1))
						done = true;
				}

				// check whether a factor exists (fix for version 1.03)
				BigInteger gcdTest = a.gcd(thisVal);
				if(gcdTest.dataLength == 1 && gcdTest.data[0] != 1)
					return false;

				// calculate a^((p-1)/2) mod p

				BigInteger expResult = a.modPow(p_sub1_shift, thisVal);
				if(expResult == p_sub1)
					expResult = -1;

				// calculate Jacobi symbol
				BigInteger jacob = Jacobi(a, thisVal);

				//Console.WriteLine("a = " + a.ToString(10) + " b = " + thisVal.ToString(10));
				//Console.WriteLine("expResult = " + expResult.ToString(10) + " Jacob = " + jacob.ToString(10));

				// if they are different then it is not prime
				if(expResult != jacob)
					return false;
			}

			return true;
		}


		//***********************************************************************
		// Implementation of the Lucas Strong Pseudo Prime test.
		//
		// Let n be an odd number with gcd(n,D) = 1, and n - J(D, n) = 2^s * d
		// with d odd and s >= 0.
		//
		// If Ud mod n = 0 or V2^r*d mod n = 0 for some 0 <= r < s, then n
		// is a strong Lucas pseudoprime with parameters (P, Q).  We select
		// P and Q based on Selfridge.
		//
		// Returns True if number is a strong Lucus pseudo prime.
		// Otherwise, returns False indicating that number is composite.
		//***********************************************************************

		public bool LucasStrongTest()
		{
			BigInteger thisVal;
			if((this.data[maxLength-1] & 0x80000000) != 0)        // negative
				thisVal = -this;
			else
				thisVal = this;

			if(thisVal.dataLength == 1)
			{
				// test small numbers
				if(thisVal.data[0] == 0 || thisVal.data[0] == 1)
					return false;
				else if(thisVal.data[0] == 2 || thisVal.data[0] == 3)
					return true;
			}

			if((thisVal.data[0] & 0x1) == 0)     // even numbers
				return false;

			return LucasStrongTestHelper(thisVal);
		}


		private bool LucasStrongTestHelper(BigInteger thisVal)
		{
			// Do the test (selects D based on Selfridge)
			// Let D be the first element of the sequence
			// 5, -7, 9, -11, 13, ... for which J(D,n) = -1
			// Let P = 1, Q = (1-D) / 4

			long D = 5, sign = -1, dCount = 0;
			bool done = false;

			while(!done)
			{
				int Jresult = BigInteger.Jacobi(D, thisVal);

				if(Jresult == -1)
					done = true;    // J(D, this) = 1
				else
				{
					if(Jresult == 0 && Math.Abs(D) < thisVal)       // divisor found
						return false;

					if(dCount == 20)
					{
						// check for square
						BigInteger root = thisVal.sqrt();
						if(root * root == thisVal)
							return false;
					}

					//Console.WriteLine(D);
					D = (Math.Abs(D) + 2) * sign;
					sign = -sign;
				}
				dCount++;
			}

			long Q = (1 - D) >> 2;

			/*
				Console.WriteLine("D = " + D);
				Console.WriteLine("Q = " + Q);
				Console.WriteLine("(n,D) = " + thisVal.gcd(D));
				Console.WriteLine("(n,Q) = " + thisVal.gcd(Q));
				Console.WriteLine("J(D|n) = " + BigInteger.Jacobi(D, thisVal));
				*/

			BigInteger p_add1 = thisVal + 1;
			int s = 0;

			for(int index = 0; index < p_add1.dataLength; index++)
			{
				uint mask = 0x01;

				for(int i = 0; i < 32; i++)
				{
					if((p_add1.data[index] & mask) != 0)
					{
						index = p_add1.dataLength;      // to break the outer loop
						break;
					}
					mask <<= 1;
					s++;
				}
			}

			BigInteger t = p_add1 >> s;

			// calculate constant = b^(2k) / m
			// for Barrett Reduction
			BigInteger constant = new BigInteger();

			int nLen = thisVal.dataLength << 1;
			constant.data[nLen] = 0x00000001;
			constant.dataLength = nLen + 1;

			constant = constant / thisVal;

			BigInteger[] lucas = LucasSequenceHelper(1, Q, t, thisVal, constant, 0);
			bool isPrime = false;

			if((lucas[0].dataLength == 1 && lucas[0].data[0] == 0) ||
				(lucas[1].dataLength == 1 && lucas[1].data[0] == 0))
			{
				// u(t) = 0 or V(t) = 0
				isPrime = true;
			}

			for(int i = 1; i < s; i++)
			{
				if(!isPrime)
				{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩在线卡一卡二| 色综合欧美在线| 成人免费毛片aaaaa**| 在线观看国产精品网站| 国产亚洲精品超碰| 亚洲国产综合在线| 成人av网站在线观看免费| 欧美一区午夜精品| 亚洲大型综合色站| 91小视频在线| 国产精品久久久久久久久免费相片| 水蜜桃久久夜色精品一区的特点| 97久久精品人人做人人爽| 国产午夜精品福利| 极品尤物av久久免费看| 91精品国产丝袜白色高跟鞋| 亚洲自拍都市欧美小说| 成人免费视频国产在线观看| 国产日韩精品一区| 国产精品一品视频| 国产三级精品视频| 国产精品正在播放| 国产亚洲成年网址在线观看| 卡一卡二国产精品| 日韩欧美一二三区| 麻豆91在线看| 欧美tickling挠脚心丨vk| 五月天久久比比资源色| 欧美日韩午夜影院| 亚洲国产乱码最新视频| 欧美亚男人的天堂| 婷婷丁香久久五月婷婷| 7777精品伊人久久久大香线蕉完整版 | 麻豆freexxxx性91精品| 91精品久久久久久蜜臀| 日韩综合小视频| 欧美一卡在线观看| 精品一区二区三区香蕉蜜桃| 精品国产麻豆免费人成网站| 国产在线精品不卡| 亚洲国产精品99久久久久久久久| 国产精品一区在线观看乱码| 国产精品色噜噜| 色偷偷久久一区二区三区| 亚洲狠狠爱一区二区三区| 欧美一区二区视频观看视频| 国产资源精品在线观看| 中文字幕成人在线观看| 色乱码一区二区三区88| 日日噜噜夜夜狠狠视频欧美人 | 欧美一区日韩一区| 加勒比av一区二区| 亚洲欧洲日本在线| 欧美老肥妇做.爰bbww视频| 男人操女人的视频在线观看欧美| 久久婷婷国产综合国色天香| 成人99免费视频| 亚洲国产综合91精品麻豆| 欧美一区二区视频在线观看2022| 国产乱子伦视频一区二区三区 | 91色porny蝌蚪| 日产国产高清一区二区三区| 久久久国产精品不卡| 97精品视频在线观看自产线路二| 夜夜嗨av一区二区三区网页| 日韩精品在线看片z| 99国产一区二区三精品乱码| 午夜欧美在线一二页| 国产亚洲一区二区三区四区| 欧美午夜影院一区| 国产精品白丝jk黑袜喷水| 一片黄亚洲嫩模| 26uuu国产电影一区二区| 日本道精品一区二区三区| 紧缚奴在线一区二区三区| 一二三四区精品视频| 国产欧美va欧美不卡在线| 欧美疯狂性受xxxxx喷水图片| 国产高清久久久| 日本人妖一区二区| 亚洲欧美日韩小说| 久久精品视频在线看| 欧美美女黄视频| 99视频精品全部免费在线| 久久av老司机精品网站导航| 一区二区三区**美女毛片| 久久久久99精品国产片| 欧美一区二区免费| 日本乱码高清不卡字幕| 成人一区二区三区| 国产一区二区三区视频在线播放| 亚洲成人av资源| 亚洲一区二区高清| 日韩毛片在线免费观看| 国产欧美精品一区二区三区四区| 日韩三级高清在线| 欧美日韩一级视频| 色94色欧美sute亚洲13| 成人av网站在线观看免费| 国产一区二区三区精品视频| 理论片日本一区| 秋霞av亚洲一区二区三| 亚洲成a人在线观看| 一区二区三区中文字幕| 亚洲日本欧美天堂| 亚洲天堂成人在线观看| 国产精品大尺度| 国产精品色婷婷久久58| 国产精品福利av| 国产精品超碰97尤物18| 国产精品美女久久久久久久网站| 欧美极品美女视频| 国产精品超碰97尤物18| 中文字幕视频一区二区三区久| 国产精品国产三级国产有无不卡| 欧美经典一区二区| 中文字幕佐山爱一区二区免费| 国产欧美精品国产国产专区| 欧美激情一区在线观看| 亚洲欧洲国产专区| 亚洲一区二区高清| 日韩国产精品91| 久久精品国产99久久6| 久88久久88久久久| 国产很黄免费观看久久| youjizz久久| 在线观看av不卡| 欧美久久久一区| 日韩免费成人网| 国产亚洲一区字幕| 一区二区在线观看免费| 婷婷综合另类小说色区| 九九九精品视频| 床上的激情91.| 91国偷自产一区二区三区成为亚洲经典| 在线亚洲免费视频| 欧美一级片免费看| 欧美经典一区二区| 亚洲亚洲精品在线观看| 毛片一区二区三区| 成人av网站免费观看| 欧美日韩综合色| 26uuu亚洲综合色欧美| 国产精品盗摄一区二区三区| 午夜精彩视频在线观看不卡| 激情国产一区二区| 色综合天天狠狠| 精品国产免费一区二区三区香蕉| 国产精品久久久久影院| 丝袜a∨在线一区二区三区不卡| 国产精一品亚洲二区在线视频| 91免费看`日韩一区二区| 91麻豆精品国产91久久久久久| 中文字幕乱码亚洲精品一区| 亚洲一区二区三区爽爽爽爽爽| 韩国毛片一区二区三区| 在线免费观看成人短视频| 久久女同互慰一区二区三区| 亚洲午夜久久久| 国产99久久久久| 91精品国产综合久久婷婷香蕉| 中文一区二区在线观看| 免费人成黄页网站在线一区二区| 成人福利视频网站| 久久亚洲私人国产精品va媚药| 一区二区成人在线视频| 成人自拍视频在线| 精品乱人伦一区二区三区| 亚洲综合在线视频| 成人小视频在线| 精品免费国产二区三区| 天天影视网天天综合色在线播放| 成人午夜在线播放| 26uuu国产日韩综合| 日韩av中文在线观看| 在线精品视频免费播放| 国产精品女上位| 国产精品123区| 精品免费国产一区二区三区四区| 亚洲成人动漫一区| 欧美丝袜丝交足nylons图片| 亚洲美女免费视频| thepron国产精品| 欧美激情在线免费观看| 国产精品白丝jk黑袜喷水| 精品欧美一区二区在线观看| 五月天激情综合| 欧美日韩一区二区欧美激情| 一级精品视频在线观看宜春院 | 香蕉影视欧美成人| 在线影视一区二区三区| 1000部国产精品成人观看| 成人午夜激情影院| 国产精品素人视频| 成人黄色一级视频| 国产精品久久久久影院亚瑟 | 亚洲国产一区二区视频| 在线视频国产一区| 一区二区三区在线视频观看58| 91免费观看视频|