资源简介
重合指数学过密码学的人都知道计算他的重要性,python实现又快又好
代码片段和文件信息
from copy import copy
from itertools import product
from tqdm import tqdm
def calcAscii(s):
i = 0
for c in s:
if ord(c) == 0x0d or (ord(c) >= 0x20 and ord(c) < 0x80):
i = i + 1
return i
def ratio(src length):
TotalOfEquals = 0
total = 0
for i in range(0 length):
for j in range(i+1 length):
total += 1
if src[i] == src[j]:
TotalOfEquals += 1
return 1.0 * TotalOfEquals / total
def CalcCoin(cipher):
clen = len(cipher)
rotioArray = []
for x in range(126):
tempfloat = 0.0
averRatio = 0.0
for n in range(x):
index = 0
tempArray = ‘‘
tempTotal = 0
m = n
while m < clen:
tempArray = tempArray + cipher[m]
tempTotal += 1
m += x
tempfloat = ratio(tempArray tempTotal)
averRatio = averRatio + tempfloat
rotioArray.append([averRatio / x x])
rotioArray.sort()
return rotioArray
encraw = open(‘file‘ ‘rb‘).read()
print CalcCoin(encraw)
‘‘‘
def psgen(minlenmaxlen=4):
iter = [
‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_!@#$%^&*()_+-=‘~[]{}\\|;\‘:“./<>?‘
#
]
for r in iter:
for repeat in range(minlenmaxlen+1):
for ps in product(rrepeat=repeat):
yield ‘‘.join(ps)
def trykey(keyencraw):
global maxfound
enc = copy(encraw)
for i in range(len(enc)):
if key[i %
评论
共有 条评论