了解Blum Blum Shub算法。(Understanding Blum Blum Shub algorithm. (Python implementation))

系统教程 行业动态 更新时间:2024-06-14 17:02:18
了解Blum Blum Shub算法。(Understanding Blum Blum Shub algorithm. (Python implementation))

请帮我理解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="

本文发布于:2023-04-21 18:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/dbc8fc686e66296f9fc04e989d5b96a7.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   Shub   Blum   Understanding   implementation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!