Implementation of a pseudorandom generator in Pyth

2019-09-04 15:30发布

I'm reading a paper called More Efficient Oblivious Transfer Extensions with Security for Malicious Adversaries by Gilad Asharov, Yehuda Lindell, Thomas Schneider and Michael Zohner.

On page 8 they present their protocol. When presenting the tools being used, they write:

pseudorandom generator G

If my understanding is correct they use a pseudorandom generator called G which takes as an input an object consisting of zeros and ones of length k and produce an object of zeros and ones of length m.

My questions is: How can I implement this in Python?

How can I implement a pseudorandom generator which takes a seed of size k and produces an output of size m?

2条回答
时光不老,我们不散
2楼-- · 2019-09-04 15:49

you can use itertools and random.choice() this one will produce out of '01' with length 40 permutations of size 39, and islice will get you first 10 out of 1000.

>>> li = list(it.islice(map(''.join,permutations('01' * 40, 39)),1000))
>>> item = random.choice(li)
>>> print(item)
010101010101010101010101010101010101010
查看更多
冷血范
3楼-- · 2019-09-04 16:10

You could just always generate a string of m ones :-) ...

Kidding apart a simple solution is to feed the input number (that will be between 0 and 2**k-1) to random.seed and then get the result from random.randrange(1<<m).

查看更多
登录 后发表回答