简体   繁体   English

python生成模数

[英]python generating numbers in modulus

i need to iteratively generate number x, which follow these conditions我需要迭代生成数字 x,它遵循这些条件

  • (x^z) mod n * x < n (x^z) mod n * x < n
  • n is known, z changes in every cycle n 已知,z 在每个循环中变化

i need it because I'm implementing timing attack on RSA, and it's needed to generate such number to measure time without modular reduction我需要它,因为我正在对 RSA 实施定时攻击,并且需要生成这样的数字来测量时间而不减少模块化
Thanks.谢谢。

If the list of z values is not known in advance you could probably try coroutine for this:如果事先不知道 z 值列表,您可以尝试使用协程:

def compute_current(x, n, z):
    # some computation here

def crunch(x, n):
    current = x
    z = yield current
    while True:
        current = compute_current(current, n, z)
        z = yield current

c = crunch(x=10)
next(c)

new_x = crunch.send(some_z)
newer_x = crunch.send(some_other_z)
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM