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

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

?? prime.c

?? 包含哈希,對稱以及非對稱的經(jīng)典算法 包含經(jīng)典事例
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* * Prime generation using the bignum library and sieving. * * Copyright (c) 1995  Colin Plumb.  All rights reserved. * For licensing and other legal details, see the file legal.c. */#if HAVE_CONFIG_H#include "config.h"#endif#if !NO_ASSERT_H#include <assert.h>#else#define assert(x) (void)0#endif#include <stdarg.h>	/* We just can't live without this... */#if BNDEBUG#include <stdio.h>#endif#include "bn.h"#include "lbnmem.h"#include "prime.h"#include "sieve.h"#include "kludge.h"/* Size of the shuffle table */#define SHUFFLE	256/* Size of the sieve area */#define SIEVE 32768u/16/* * Helper function that does the slow primality test. * bn is the input bignum; a and e are temporary buffers that are * allocated by the caller to save overhead. * * Returns 0 if prime, >0 if not prime, and -1 on error (out of memory). * If not prime, returns the number of modular exponentiations performed. * Calls the fiven progress function with a '*' for each primality test * that is passed. * * The testing consists of strong pseudoprimality tests, to the bases * 2, 3, 5, 7, 11, 13 and 17.  (Also called Miller-Rabin, although that's * not technically correct if we're using fixed bases.)  Some people worry * that this might not be enough.  Number theorists may wish to generate * primality proofs, but for random inputs, this returns non-primes with a * probability which is quite negligible, which is good enough. * * It has been proved (see Carl Pomerance, "On the Distribution of * Pseudoprimes", Math. Comp. v.37 (1981) pp. 587-593) that the number * of pseudoprimes (composite numbers that pass a Fermat test to the * base 2) less than x is bounded by: * exp(ln(x)^(5/14)) <= P_2(x)	### CHECK THIS FORMULA - it looks wrong! ### * P_2(x) <= x * exp(-1/2 * ln(x) * ln(ln(ln(x))) / ln(ln(x))). * Thus, the local density of Pseudoprimes near x is at most * exp(-1/2 * ln(x) * ln(ln(ln(x))) / ln(ln(x))), and at least * exp(ln(x)^(5/14) - ln(x)).  Here are some values of this function * for various k-bit numbers x = 2^k: * Bits	Density <=	Bit equivalent	Density >=	Bit equivalent *  128	3.577869e-07	 21.414396	4.202213e-37	 120.840190 *  192	4.175629e-10	 31.157288	4.936250e-56	 183.724558 *  256 5.804314e-13	 40.647940	4.977813e-75	 246.829095 *  384 1.578039e-18	 59.136573	3.938861e-113	 373.400096 *  512 5.858255e-24	 77.175803	2.563353e-151	 500.253110 *  768 1.489276e-34	112.370944	7.872825e-228	 754.422724 * 1024 6.633188e-45	146.757062	1.882404e-304	1008.953565 * * As you can see, there's quite a bit of slop between these estimates. * In fact, the density of pseudoprimes is conjectured to be closer * to the square of that upper bound.  E.g. the density of pseudoprimes * of size 256 is around 3 * 10^-27.  The density of primes is very * high, from 0.005636 at 256 bits to 0.001409 at 1024 bits, i.e. * more than 10^-3. * * For those people used to cryptographic levels of security where the * 56 bits of DES key space is too small because it's exhaustible with * custom hardware searching engines, note that you are not generating * 50,000,000 primes per second on each of 56,000 custom hardware chips * for several hours.  The chances that another Dinosaur Killer asteroid * will land today is about 10^-11 or 2^-36, so it would be better to * spend your time worrying about *that*.  Well, okay, there should be * some derating for the chance that astronomers haven't seen it yet, but * I think you get the idea.  For a good feel about the probability of * various events, I have heard that a good book is by E'mile Borel, * "Les Probabilite's et la vie".  (The 's are accents, not apostrophes.) * * For more on the subject, try "Finding Four Million Large Random Primes", * by Ronald Rivest, in Advancess in Cryptology: Proceedings of Crypto '90. * He used a small-divisor test, then a Fermat test to the base 2, and then * 8 iterations of a Miller-Rabin test.  About 718 million random 256-bit * integers were generated, 43,741,404 passed the small divisor test, * 4,058,000 passed the Fermat test, and all 4,058,000 passed all 8 * iterations of the Miller-Rabin test, proving their primality beyond most * reasonable doubts. * * If the probability of getting a pseudoprime is some small p, then * the probability of not getting it in t trials is (1-p)^t.  Remember * that, for small p, (1-p)^(1/p) ~ 1/e, the base of natural logarithms. * (This is more commonly expressed as e = lim_{x\to\infty} (1+1/x)^x.) * Thus, (1-p)^t ~ e^(-p*t) = exp(-p*t).  So the odds of being able to * do this many tests without seeing a pseudoprime if you assume that * p = 10^-6 (one in a million) is one in 57.86.  If you assume that * p = 2*10^-6, it's one in 3347.6.  So it's implausible that the * density of pseudoprimes is much more than one millionth the density * of primes. * * He also gives a theoretical argument that the chance of finding a * 256-bit non-prime which satisfies one Fermat test to the base 2 is less * than 10^-22.  The small divisor test improves this number, and if the * numbers are 512 bits (as needed for a 1024-bit key) the odds of failure * shrink to about 10^-44.  Thus, he concludes, for practical purposes * *one* Fermat test to the base 2 is sufficient. */static intprimeTest(struct BigNum const *bn, struct BigNum *e, struct BigNum *a,	int (*f)(void *arg, int c), void *arg){	unsigned i, j;	unsigned k, l;	int err;	static unsigned const primes[] = {2, 3, 5, 7, 11, 13, 17};#if BNDEBUG	/* Debugging */	/*	 * This is debugging code to test the sieving stage.	 * If the sieving is wrong, it will let past numbers with	 * small divisors.  The prime test here will still work, and	 * weed them out, but you'll be doing a lot more slow tests,	 * and presumably excluding from consideration some other numbers	 * which might be prime.  This check just verifies that none	 * of the candidates have any small divisors.  If this	 * code is enabled and never triggers, you can feel quite	 * confident that the sieving is doing its job.	 */	i = bnModQ(bn, 30030);	/* 30030 = 2 * 3 * 5 * 7 * 11 * 13 */	if (!(i % 2)) printf("bn div by 2!");	if (!(i % 3)) printf("bn div by 3!");	if (!(i % 5)) printf("bn div by 5!");	if (!(i % 7)) printf("bn div by 7!");	if (!(i % 11)) printf("bn div by 11!");	if (!(i % 13)) printf("bn div by 13!");	i = bnModQ(bn, 7429);	/* 7429 = 17 * 19 * 23 */	if (!(i % 17)) printf("bn div by 17!");	if (!(i % 19)) printf("bn div by 19!");	if (!(i % 23)) printf("bn div by 23!");	i = bnModQ(bn, 33263);	/* 33263 = 29 * 31 * 37 */	if (!(i % 29)) printf("bn div by 29!");	if (!(i % 31)) printf("bn div by 31!");	if (!(i % 37)) printf("bn div by 37!");#endif	/*	 * Now, check that bn is prime.  If it passes to the base 2,	 * it's prime beyond all reasonable doubt, and everything else	 * is just gravy, but it gives people warm fuzzies to do it.	 *	 * This starts with verifying Euler's criterion for a base of 2.	 * This is the fastest pseudoprimality test that I know of,	 * saving a modular squaring over a Fermat test, as well as	 * being stronger.  7/8 of the time, it's as strong as a strong	 * pseudoprimality test, too.  (The exception being when bn ==	 * 1 mod 8 and 2 is a quartic residue, i.e. bn is of the form	 * a^2 + (8*b)^2.)  The precise series of tricks used here is	 * not documented anywhere, so here's an explanation.	 * Euler's criterion states that if p is prime then a^((p-1)/2)	 * is congruent to Jacobi(a,p), modulo p.  Jacobi(a,p) is	 * a function which is +1 if a is a square modulo p, and -1 if	 * it is not.  For a = 2, this is particularly simple.  It's	 * +1 if p == +/-1 (mod 8), and -1 if m == +/-3 (mod 8).	 * If p == 3 mod 4, then all a strong test does is compute	 * 2^((p-1)/2). and see if it's +1 or -1.  (Euler's criterion	 * says *which* it should be.)  If p == 5 (mod 8), then	 * 2^((p-1)/2) is -1, so the initial step in a strong test,	 * looking at 2^((p-1)/4), is wasted - you're not going to	 * find a +/-1 before then if it *is* prime, and it shouldn't	 * have either of those values if it isn't.  So don't bother.	 *	 * The remaining case is p == 1 (mod 8).  In this case, we	 * expect 2^((p-1)/2) == 1 (mod p), so we expect that the	 * square root of this, 2^((p-1)/4), will be +/-1 (mod p).	 * Evaluating this saves us a modular squaring 1/4 of the time.	 * If it's -1, a strong pseudoprimality test would call p	 * prime as well.  Only if the result is +1, indicating that	 * 2 is not only a quadratic residue, but a quartic one as well,	 * does a strong pseudoprimality test verify more things than	 * this test does.  Good enough.	 *	 * We could back that down another step, looking at 2^((p-1)/8)	 * if there was a cheap way to determine if 2 were expected to	 * be a quartic residue or not.  Dirichlet proved that 2 is	 * a quartic residue iff p is of the form a^2 + (8*b^2).	 * All primes == 1 (mod 4) can be expressed as a^2 + (2*b)^2,	 * but I see no cheap way to evaluate this condition.	 */	if (bnCopy(e, bn) < 0)		return -1;	(void)bnSubQ(e, 1);	l = bnLSWord(e);	j = 1;	/* Where to start in prime array for strong prime tests */	if (l & 7) {		bnRShift(e, 1);		if (bnTwoExpMod(a, e, bn) < 0)			return -1;		if ((l & 7) == 6) {			/* bn == 7 mod 8, expect +1 */			if (bnBits(a) != 1)				return 1;	/* Not prime */			k = 1;		} else {			/* bn == 3 or 5 mod 8, expect -1 == bn-1 */			if (bnAddQ(a, 1) < 0)				return -1;			if (bnCmp(a, bn) != 0)				return 1;	/* Not prime */			k = 1;			if (l & 4) {				/* bn == 5 mod 8, make odd for strong tests */				bnRShift(e, 1);				k = 2;			}		}	} else {		/* bn == 1 mod 8, expect 2^((bn-1)/4) == +/-1 mod bn */		bnRShift(e, 2);		if (bnTwoExpMod(a, e, bn) < 0)			return -1;		if (bnBits(a) == 1) {			j = 0;	/* Re-do strong prime test to base 2 */		} else {			if (bnAddQ(a, 1) < 0)				return -1;			if (bnCmp(a, bn) != 0)				return 1;	/* Not prime */		}		k = 2 + bnMakeOdd(e);	}	/* It's prime!  Now go on to confirmation tests */	/*	 * Now, e = (bn-1)/2^k is odd.  k >= 1, and has a given value	 * with probability 2^-k, so its expected value is 2.	 * j = 1 in the usual case when the previous test was as good as	 * a strong prime test, but 1/8 of the time, j = 0 because	 * the strong prime test to the base 2 needs to be re-done.	 */	for (i = j; i < sizeof(primes)/sizeof(*primes); i++) {		if (f && (err = f(arg, '*')) < 0)			return err;		(void)bnSetQ(a, primes[i]);		if (bnExpMod(a, a, e, bn) < 0)			return -1;		if (bnBits(a) == 1)			continue;	/* Passed this test */		l = k;		for (;;) {			if (bnAddQ(a, 1) < 0)				return -1;			if (bnCmp(a, bn) == 0)	/* Was result bn-1? */				break;	/* Prime */			if (!--l)	/* Reached end, not -1? luck? */				return i+2-j;	/* Failed, not prime */			/* This portion is executed, on average, once. */			(void)bnSubQ(a, 1);	/* Put a back where it was. */			if (bnSquare(a, a) < 0 || bnMod(a, a, bn) < 0)				return -1;			if (bnBits(a) == 1)				return i+2-j;	/* Failed, not prime */		}		/* It worked (to the base primes[i]) */	}		/* Yes, we've decided that it's prime. */	if (f && (err = f(arg, '*')) < 0)		return err;	return 0;	/* Prime! */}/* * Modifies the bignum to return a nearby (slightly larger) number which * is a probable prime.  Returns >=0 on success or -1 on failure (out of * memory).  The return value is the number of unsuccessful modular * exponentiations performed.  This never gives up searching. * * All other arguments are optional.  They may be NULL.  They are: * * unsigned (*rand)(unsigned limit) * For better distributed numbers, supply a non-null pointer to a * function which returns a random x, 0 <= x < limit.  (It may make it * simpler to know that 0 < limit <= SHUFFLE, so you need at most a byte.) * The program generates a large window of sieve data and then does * pseudoprimality tests on the data.  If a rand function is supplied, * the candidates which survive sieving are shuffled with a window of * size SHUFFLE before testing to increase the uniformity of the prime * selection.  This isn't perfect, but it reduces the correlation between * the size of the prime-free gap before a prime and the probability * that that prime will be found by a sequential search. * * If rand is NULL, sequential search is used.  If you want sequential * search, note that the search begins with the given number; if you're * trying to generate consecutive primes, you must increment the previous * one by two before calling this again. * * int (*f)(void *arg, int c), void *arg * The function f argument, if non-NULL, is called with progress indicator * characters for printing.  A dot (.) is written every time a primality test * is failed, a star (*) every time one is passed, and a slash (/) in the * (very rare) case that the sieve was emptied without finding a prime * and is being refilled.  f is also passed the void *arg argument for * private context storage.  If f returns < 0, the test aborts and returns * that value immediately. * * The "exponent" argument, and following unsigned numbers, are exponents * for which an inverse is desired, modulo p.  For a d to exist such that

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美在线|欧美| 成人不卡免费av| 亚洲资源中文字幕| 亚洲日本va午夜在线电影| 国产精品久久福利| 亚洲欧美日本在线| 亚洲国产cao| 婷婷国产v国产偷v亚洲高清| 奇米精品一区二区三区在线观看一| 亚洲高清免费观看| 精品一区二区三区欧美| 国产成a人亚洲精| yourporn久久国产精品| 欧美日韩一区二区三区在线| 欧美喷潮久久久xxxxx| 日韩女优制服丝袜电影| 久久久久久久久免费| 国产精品成人免费精品自在线观看| 亚洲蜜臀av乱码久久精品 | 国产高清不卡一区二区| 国产精品18久久久久久久久 | 亚洲网友自拍偷拍| 久久精品国产亚洲高清剧情介绍| 国产精品自产自拍| 在线观看区一区二| 精品欧美乱码久久久久久1区2区| 亚洲国产成人一区二区三区| 一区二区在线电影| 九一九一国产精品| 在线免费观看日本欧美| 精品99一区二区| 亚洲美女视频在线| 毛片av中文字幕一区二区| 国产suv精品一区二区三区| 欧美日韩中文字幕一区| 国产午夜精品一区二区三区嫩草| 亚洲综合色在线| 国产精品一区二区在线观看不卡| 色婷婷久久综合| 久久亚洲一级片| 日日摸夜夜添夜夜添国产精品| 成人国产免费视频| 日韩免费观看高清完整版| 中文字幕在线一区二区三区| 麻豆成人综合网| 欧美日韩小视频| 亚洲欧美激情在线| 国产成人综合在线观看| 91精品黄色片免费大全| 亚洲永久精品国产| 99九九99九九九视频精品| 久久精品一区二区三区不卡牛牛| 亚洲国产美女搞黄色| 99riav久久精品riav| 久久品道一品道久久精品| 免费成人av资源网| 在线电影院国产精品| 亚洲黄色片在线观看| av激情综合网| 国产精品乱码人人做人人爱| 国产成人精品三级麻豆| 久久久久国产免费免费| 国内成+人亚洲+欧美+综合在线| 欧美久久久久久蜜桃| 亚洲永久精品国产| 欧美日韩一级大片网址| 亚洲高清免费观看高清完整版在线观看| 99久久精品国产一区二区三区 | 亚洲精品成人天堂一二三| 国产精品99久久久久久宅男| 欧美成人伊人久久综合网| 青青草一区二区三区| 日韩欧美一区二区久久婷婷| 免费在线观看一区| 精品国产91久久久久久久妲己| 久久精品国产99国产| 久久精品视频在线看| 国产成人精品免费在线| 国产精品久久福利| 日本高清不卡视频| 亚洲高清免费视频| 日韩色在线观看| 国产一区二区不卡老阿姨| 国产亚洲一本大道中文在线| 成人午夜免费视频| 亚洲美女免费视频| 欧美日韩在线播| 久久99久久99精品免视看婷婷 | 免费观看30秒视频久久| 日韩欧美激情在线| 国产jizzjizz一区二区| 亚洲美女精品一区| 91精品国产综合久久精品app| 九九**精品视频免费播放| 国产精品私人自拍| 欧洲另类一二三四区| 精品一区二区三区日韩| 国产精品免费视频观看| 欧美天天综合网| 国产精品一区二区在线观看不卡| 国产精品美女久久久久av爽李琼| 一本大道av伊人久久综合| 美国毛片一区二区三区| 中文字幕一区二区三区在线观看| 欧美色综合久久| 国产美女视频91| 亚洲午夜一区二区三区| 2021国产精品久久精品| 日本韩国精品在线| 国产很黄免费观看久久| 亚洲成人综合在线| 国产精品欧美一级免费| 欧美一区二区三区不卡| 99精品国产99久久久久久白柏 | 成人福利视频网站| 亚洲成人激情av| 国产夜色精品一区二区av| 51午夜精品国产| 91麻豆国产精品久久| 国产综合一区二区| 亚洲成a人v欧美综合天堂| 国产精品无人区| 精品国产成人在线影院 | 91在线精品一区二区三区| 美国欧美日韩国产在线播放| 夜夜夜精品看看| 亚洲国产高清在线| 亚洲精品在线观看网站| 日韩一区二区精品葵司在线| 欧美性色综合网| 色婷婷综合激情| 99久久伊人网影院| 盗摄精品av一区二区三区| 精品亚洲成a人在线观看| 午夜视黄欧洲亚洲| 亚洲综合激情网| 亚洲欧美日韩中文字幕一区二区三区| 久久伊人蜜桃av一区二区| 精品欧美一区二区在线观看| 91精品国产美女浴室洗澡无遮挡| 欧美性受xxxx| 欧美日本在线视频| 欧美性色黄大片| 欧美日韩日日夜夜| 制服丝袜日韩国产| 欧美一区二区久久| 日韩一区国产二区欧美三区| 91精品国产综合久久福利软件| 欧美日韩一本到| 欧美肥胖老妇做爰| 日韩视频在线你懂得| 日韩一区二区在线看片| 欧美一区二区视频在线观看| 制服丝袜在线91| 精品成人免费观看| 国产精品午夜在线| 亚洲视频在线观看三级| 成人欧美一区二区三区在线播放| 国产精品久久久久久久浪潮网站 | 欧美丰满一区二区免费视频| 日韩亚洲欧美在线| 久久青草欧美一区二区三区| 国产亚洲自拍一区| 亚洲人快播电影网| 视频一区欧美精品| 久久91精品国产91久久小草| 国产99久久久国产精品潘金网站| 成人国产亚洲欧美成人综合网| 91蜜桃婷婷狠狠久久综合9色| 91久久香蕉国产日韩欧美9色| 欧美日韩日日夜夜| 精品区一区二区| 最新国产精品久久精品| 亚洲福利一区二区| 国产真实乱偷精品视频免| 成人国产精品免费观看视频| 欧美亚洲尤物久久| 日韩免费看的电影| 中文字幕av一区二区三区| 亚洲第一福利视频在线| 国产在线精品国自产拍免费| 99这里都是精品| 91精品国产乱| 亚洲欧美在线视频观看| 免费观看一级特黄欧美大片| 成人国产精品免费网站| 91精品国产一区二区| 国产三级欧美三级日产三级99| 一区二区三区色| 国产乱对白刺激视频不卡| 在线免费观看一区| 国产午夜精品久久久久久久 | 综合av第一页| 久久国产日韩欧美精品| 日本电影欧美片| 国产日产欧产精品推荐色| 日韩精品1区2区3区| av在线这里只有精品| 久久在线免费观看| 偷窥少妇高潮呻吟av久久免费|