用簡單的代碼解決
uj5u.com熱心網友回復:
如果明文是小寫字母,則轉換為大寫字母加什么?uj5u.com熱心網友回復:
def Kaisa_crack(obj):
word_list = ['A','B','C','D','E','F','G',
'H','I','J','K','L','M','N','O','P','Q',
'R','S','T','U','V','W','X','Y','Z']
translation = ''
n = 1
for word in obj:
if word in word_list:
word_index = word_list.index(word) #判斷當前字母索引值
word_crack_index = (n + word_index) % 26 #找出破解后單詞字母表的索引值
crack_word = word_list[word_crack_index] #給破解后字母賦值
translation += crack_word #字符拼接
elif word.upper() in word_list:
pass #填入如果是小寫字母的要求
else:
translation += word #其他字串原樣輸出
n += 1
print(translation)
Kaisa_crack('IWASLEANINGPYTHON')
輸出的結果是:JYDWQKHVRXRBLHWEE
uj5u.com熱心網友回復:
首先把每個字母進行編碼得到基礎數字 number,其范圍為1-26;假設字母在字串種的位置為index,該字母經編碼后的數字將是:number + index +1;
最后得到余數 result_number = (number + index + 1) / 26的余數。
余數的范圍為0-25,對應的字母為Z,A,B...Y。
實作方式不難,我也是新手,不行就用if else就可以得出結果了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/127583.html
上一篇:uvm使用相關問題,求大佬解答啊
