我正在做一个项目,这个错误不断出现:
class PRNG:
def __init__(self):
# parameters
# P-256 prime
self.p=115792089210356248762697446949407573530086143415290314195533631308867097853951
self.a=self.p-3
self.b=41058363725152142129326129780047268409114441015993725554835256314039467401291
self.E=curve(self.a,self.b,self.p)
self.E.n=115792089210356248762697446949407573529996955224135760342422259061068512044369
self.P=point(0,46263761741508638697010950048709651021688891777877937875096931459006746039284)
self.k=183521403747637560534595403690771364941493702673414885451510208165414833985
self.Q=mult(self.k,self.P,self.E)
self.t=bytes_to_int(os.urandom(32)) # initial seed
#print self.t
self.output_length=240
self.truncate_length=16
def function_attack(self, nbytes, predicted_state):
calls = ((nbytes*8-1)/self.output_length)+1
out = ''
for i in xrange(calls):
tP=mult(predicted_state,self.P,self.E)
s=tP.x
sQ=mult(s,self.Q,self.E)
r=sQ.x
r_out=r % (2**self.output_length)
self.t=s
out = out + int_to_bytes(r_out, self.output_length/8)
return out[:nbytes]
def function(self, nbytes):
calls = ((nbytes*8-1)/self.output_length)+1
out = ''
for i in xrange(calls):
tP=mult(self.t,self.P,self.E)
s=tP.x
sQ=mult(s,self.Q,self.E)
r=sQ.x
r_out=r % (2**self.output_length)
self.t=s
out = out + int_to_bytes(r_out, self.output_length/8)
return out[:nbytes]
第一种方法在单独的文件中调用,输出始终如下(无论我是否更改局部变量调用的名称):
File "C:file1.py", line 32, in <module>
prng = PRNG()
File "C:file_where_error_occurs.py", line 286, in __init__
for i in xrange(calls):
NameError: global name 'calls' is not defined
python在做什么?
您有缩进错误...这通常是由混合制表符和空格引起的...大多数体面的编辑器都可以轻松为您解决此问题......要查看缩进错误,请运行程序
python -tt my_program.py