即使条件不满足,孩子似乎总是将自己设置为平等的父母。有什么帮助吗?是因为分层吗?
def crack(ct):
temp = 10 + 0.087 * (len(ct)-84)
fit = ns.ngram_score('english_quadgrams.txt')
while 1 == 1:
parent = randkey()
counter = 0
while counter < 50000:
ps = fit.score((de(ct,parent)).upper())
number = rd.randint(1,25)
if number == 1:
child = nw(parent)
else:
if number == 2:
child = td(parent)
else:
if number == 3:
child = lr(parent)
else:
if number == 4:
child = randr(parent)
else:
if number == 5:
child = randc(parent)
else:
child = rand2(parent)
print(de(ct,child))
cs = fit.score((de(ct,child)).upper())
diff = ps-cs
print(ps,cs, diff)
prob = 1/(math.exp(diff/temp))
print(prob)
random = rd.uniform(0,1)
print(random)
if diff < 0:
parent = child
elif prob < random:
counter = counter + 1
else:
parent = child
基于quadgram rating文本和基于此处的库计算分数。任何建议都会有所帮助。