请帮我理解BBS算法。 我做了这个实现:
class EmptySequenseError(Exception): pass class BlumBlumShub(object): def __init__(self, length): self.length = length self.primes = e(1000) # Primes obtained by my own Sieve of Eratosthenes implementation. def get_primes(self): out_primes = [] while len(out_primes) < 2: curr_prime = self.primes.pop() if curr_prime % 4 == 3: out_primes.append(curr_prime) return out_primes def set_random_sequence(self): p, q = self.get_primes() m = p * q self.random_sequence = [((x+1)**2)%m for x in range(self.length)] def get_random_sequence(self): if self.random_sequence: return self.random_sequence raise EmptySequenseError("Set random sequence before get it!")我有几个问题。 起初我不想使用random库,这太天真了。 我的顺序在增加,它不是绝对随机的。 如何防止返回序列增加? 我不明白这部分的算法描述:
在算法的每一步,一些输出从x n + 1导出; 输出通常是x n + 1的位奇偶校验或x n + 1的一个或多个最低有效位。
请向我解释这是什么意思?
编辑总结:
该算法已得到纠正。 引用替换为en.wikipedia报价。Please help me to understand BBS algorithm. I did this implementation:
class EmptySequenseError(Exception): pass class BlumBlumShub(object): def __init__(self, length): self.length = length self.primes = e(1000) # Primes obtained by my own Sieve of Eratosthenes implementation. def get_primes(self): out_primes = [] while len(out_primes) < 2: curr_prime = self.primes.pop() if curr_prime % 4 == 3: out_primes.append(curr_prime) return out_primes def set_random_sequence(self): p, q = self.get_primes() m = p * q self.random_sequence = [((x+1)**2)%m for x in range(self.length)] def get_random_sequence(self): if self.random_sequence: return self.random_sequence raise EmptySequenseError("Set random sequence before get it!")And I have several questions. At first I do not want to use random library, it is too naive. My sequence is increasing, it is not absolutely random. How to prevent increasing in returned sequence? And I do not understand this part of the algorithm description:
At each step of the algorithm, some output is derived from xn+1; the output is commonly either the bit parity of xn+1 or one or more of the least significant bits of xn+1.
Please explain to me what does it mean?
Edit summary:
The algorithm is corrected. Quote substituted to en.wikipedia quote.更多推荐
self,random,算法,algorithm,def,电脑培训,计算机培训,IT培训"/> <meta name="
发布评论