密码随机数 [英] Cryptographically random numbers

查看:116
本文介绍了密码随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在努力从一系列数字开发一个简单的,加密安全的

数字(正如人们可能会找到大的

数字,测试他们是否是素数)。我的功能如下:


def cran_rand(min,max):

if(min> max):

x = max

max = min

min = x

range = round(log(max-min)/ log(256))

如果范围== 0:

范围= 1

num = max + 1

while(num> max):

num = min + s2num(urandom(range))

返回数字


对此有何评论?我认为它应该坚持到一个测试,似乎

工作正常。谢谢!

Okay, I''m working on devoloping a simple, cryptographically secure
number, from a range of numbers (As one might do for finding large
numbers, to test if they are prime). My function looks like this:

def cran_rand(min,max):
if(min>max):
x=max
max=min
min=x
range=round(log(max-min)/log(256))
if range==0:
range=1
num=max+1
while(num>max):
num=min+s2num(urandom(range))
return num

Any comments on this? I think it should hold up to a test, it seems to
work alright. Thanks!

推荐答案

> def cran_rand(min,max):


你在这里隐藏内置插件。不是问题,但是我一般会把b
避免。

> def cran_rand(min,max):

You''re shadowing built-ins here. Not a problem, but something I''d generally
avoid.

if(min> max):
x = max
max = min
min = x


如果args是a,b你可以说:


maxarg,minarg = min(a,b),max(a,b)


range = round(log(max-min)/ log(256))


更多内置阴影...

如果范围== 0:
范围= 1


或as alt_name_for_range = ...或1

num = max + 1
while(num> max):
num = min + s2num(urandom(range))


我会假设os.urandom是urandom。什么是s2num?

返回数字

对此有何评论?我认为它应该经得起考验,似乎工作正常。谢谢!
if(min>max):
x=max
max=min
min=x
If the args were a,b you could say:

maxarg,minarg = min(a,b),max(a,b)

range=round(log(max-min)/log(256))
more builtin shadowing...
if range==0:
range=1
or as alt_name_for_range=... or 1
num=max+1
while(num>max):
num=min+s2num(urandom(range))
I''ll assume os.urandom is urandom. What''s s2num?
return num

Any comments on this? I think it should hold up to a test, it seems to
work alright. Thanks!



如果这样做你想要的,这很好。但总有一天当你再看一遍

并看到


而(num> gt):num = min + s2num(urandom(range))


你会想知道...


谢天谢地-python-uses-int-and-not-num-ly y''rs,


Emile van Sebille
em***@fenx.com




If this does what you want, that''s good. But someday when you look again
and see

while(num>max): num=min+s2num(urandom(range))

you''ll wonder...

Thankfully-python-uses-int-and-not-num-ly y''rs,

Emile van Sebille
em***@fenx.com




关于max和min值的好主意。是的,urandom是os.urandom。

s2num(''blah'')会将短语blah转换为ascii,并将它们视为

如果它们是一个很大的功能。


其他任何仍然感兴趣的人,我发现了另一个小虫子,但是

是模块化的(再次)。它不会做太多,但是......


我从头到尾测试了RSA,发现了另一个小虫子(我估算了
)文本luke,它解密到ekul),但它现在很好用

。希望没有什么可以留下的,谢谢你的帮助!

Good idea about the max and min values. Yes, urandom is os.urandom.
s2num(''blah'') will convert the phrase blah to ascii, and treat them as
if they were a big function.

Anyone else whose still interested, I found another small bug, but it
was in the modular (Again). It won''t do much, but...

I did test out the RSA from end to end, found another small bug (I
imputed the text luke, and it decrypted to ekul), but it works good
now. Hopefully there''s nothing left gaping, thanks for the help!


Tuvas写道:
好的,我是致力于从一系列数字中开发一个简单的,加密安全的数字(正如人们可能会找到大数字,以测试它们是否是素数)。我的功能如下:

def cran_rand(min,max):
if(min> gt max):
x = max
max = min min = x
range = round(log(max-min)/ log(256))
如果range == 0:
range = 1
num = max + 1
while(num> max):
num = min + s2num(urandom(range))
return num

对此有何评论?我认为它应该经得起考验,似乎工作正常。
Okay, I''m working on devoloping a simple, cryptographically secure
number, from a range of numbers (As one might do for finding large
numbers, to test if they are prime). My function looks like this:

def cran_rand(min,max):
if(min>max):
x=max
max=min
min=x
range=round(log(max-min)/log(256))
if range==0:
range=1
num=max+1
while(num>max):
num=min+s2num(urandom(range))
return num

Any comments on this? I think it should hold up to a test, it seems to
work alright.




不得不反对。尝试:


for _ in range(100):

print cran_rand(0,500)


如何很多大于255的数字?

我有更多的评论,但这是最大的问题。

-

- -Bryan



Have to disagree. Try:

for _ in range(100):
print cran_rand(0, 500)

How many numbers greater than 255 do you get?
I have more comments, but that''s the biggest issue.
--
--Bryan


这篇关于密码随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆