我完全不知道該如何按照題中要求去解密檔案,不知道從哪里著手,連思路都不清晰
uj5u.com熱心網友回復:
s = 'abedgf'
encrypted = []
for num, strs in enumerate(s):
encrypted.append(chr((ord(strs)-num-1)%10))
print(encrypted)
uj5u.com熱心網友回復:
string = 'abcdefgefghigklmnopqrestuvwxyz'
encrypted = []
# 加密字串string
for index_num, char in enumerate(string):
# print(ord(char),index_num,end=' ')
# print((ord(char)-index_num)%10)
encrypted.append(chr((ord(char) - index_num) % 10))
# 寫進txt檔案中
with open('encryptedfile.txt', 'w+') as f:
for i in encrypted:
f.write(str(i))
# 打開txt檔案,進行解密
decode_str = ''
with open('encryptedfile.txt', 'r') as f:
decode = f.read()
# 解密讀取到的字符
for index_num, char in enumerate(decode):
# 不要問我9從哪里來的,9是猜的,商乘除數加余數等于被除數,是除數可能是9
decode_str += chr(ord(char) + 9 * 10 + index_num)
print(decode_str)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/49895.html
