本文整理匯總了Python中Text.Text.clean_string方法的典型用法代碼示例。如果您正苦於以下問題:Python Text.clean_string方法的具體用法?Python Text.clean_string怎麽用?Python Text.clean_string使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Text.Text
的用法示例。
在下文中一共展示了Text.clean_string方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __guess_key
# 需要導入模塊: from Text import Text [as 別名]
# 或者: from Text.Text import clean_string [as 別名]
def __guess_key(self, min_len=1, max_len=9, display=False):
keylen = self.guess_key_length(min_len, max_len, display)
if keylen == 0:
print "[!] No key length found."
return -1
if display:
print "[*] Most probable key length : " + str(keylen) + "\n"
freq_fr = {'e': 14.715, 's': 7.948, 'a': 7.636, 'i': 7.529, 't': 7.244, 'n': 7.095, 'r': 6.553, 'u': 6.311, 'l': 5.456, 'o': 5.378, 'd': 3.669, 'c': 3.260, 'p': 3.021, 'm': 2.968, 'v': 1.628, 'q': 1.362, 'f': 1.066, 'b': 0.901, 'g': 0.866, 'h': 0.737, 'j': 0.545, 'x': 0.387, 'y': 0.308, 'z': 0.136, 'w': 0.114, 'k': 0.049}
password = ""
for i in range(keylen):
sub_alphabet = VigenereCipher(''.join([self._s[keylen*j + i] for j in range(self._len//keylen)]))
min_differential = 99999
password_letter = ""
for c in range(65, 65+26):
sub_alphabet.key = chr(c)
decrypted = VigenereCipher(sub_alphabet.decipher().tostring())
sub_alphabet.encipher()
freq_s = { k:round((v/decrypted.len)*100, 3) for k,v in dict(decrypted.get_frequencies()).items()}
differential = sum([abs(freq_fr[k.lower()]-v) for k,v in freq_s.items()])
if differential < min_differential:
min_differential = differential
password_letter = chr(c)
password += password_letter
# Little hack for repetitive password due to frequency analysis
for i in range(1, len(password)):
if len(password) % i == 0:
duplicate = True
s = [password[j*i:(j+1)*i] for j in range(len(password)//i)]
ex_prec = s[0]
for ex in s:
if ex != ex_prec:
duplicate = False
break
ex_prec = ex
if duplicate:
password = ex
if display:
print "[*] [UPDATE] Most probable key length : " + str(len(password)) + "\n"
break
return Text.clean_string(password)