import sysdef encrypt(strng, key):encrypted = ''for x in strng:indx = (ord(x) + key) % 256if indx > 126:indx = indx - 95encrypted = encrypted + chr(indx)return encrypteddef decrypt(strng, key):decrypted = ''for x in strng:indx = (ord(x) - key) % 256if indx < 32:indx = indx + 95decrypted = decrypted + chr(indx)return decrypteddef brute_force(strng):key = 1decrypted = ''while key <= 94:for x in strng:indx = (ord(x) - key) % 256if indx < 32:indx = indx + 95decrypted = decrypted + chr(indx)print("Key: {}\t| Message: {}".format(key, decrypted))decrypted = ''key += 1return Nonedef main():while True:print('-' * 10 + "\n**Menu**\n" + '-' * 10)print("1.Encrpyt")print("2.Decrypt")print("3.BruteForce")print("4.Quit")choice = input("What would you like to do?: ")if choice not in ['1', '2', '3', '4']:print ("Invalid choice, please enter a valid choice")elif choice == '1':strng = input("Please enter the string to be encrypted: ")key = int(input("Please enter off-set between 1-94: "))if key in range(1, 95):print (encrypt(strng.lower(), key))elif choice == '2':strng = input("Please enter the string to be decrypted: ")key = int(input("Please enter off-set between 1-94: "))if key in range(1,95):print(decrypt(strng, key))elif choice == '3':strng = input("Please enter the string to be decrypted: ")brute_force(strng)main()elif choice == '4':print ("Goodbye.")breakmain()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。