导图社区 加密和解密
这是一个关于加密和解密的思维导图,加密与解密是信息安全领域中的基本概念,用于保护数据的机密性。
社区模板帮助中心,点此进入>>
互联网9大思维
组织架构-单商户商城webAPP 思维导图。
域控上线
python思维导图
css
CSS
计算机操作系统思维导图
计算机组成原理
IMX6UL(A7)
考试学情分析系统
加密和解密
加密程序
import random def caesar_cipher_encrypt(text, shift): encrypted_text = "" for char in text: if char.isalpha(): shifted = ord(char) + shift if char.islower(): if shifted > ord('z'): shifted -= 26 elif char.isupper(): if shifted > ord('Z'): shifted -= 26 encrypted_text += chr(shifted) else: encrypted_text += char return encrypted_text def random_special_char(): special_chars = "!@#$%^&*()-_=+[]{}|;':\",.<>/?" return random.choice(special_chars) def multi_round_encrypt(text, shifts): encrypted_text = text for shift in shifts: encrypted_text = caesar_cipher_encrypt(encrypted_text, shift) encrypted_text = ''.join([random_special_char() + char for char in encrypted_text]) return encrypted_text text = input("请输入要加密的文本:") shifts = [int(input("请输入第{}轮的偏移量:".format(i+1))) for i in range(3)] encrypted_text = multi_round_encrypt(text, shifts) print("加密后的文本:", encrypted_text)
解密程序
def caesar_cipher_decrypt(text, shift): decrypted_text = "" for char in text: if char.isalpha(): shifted = ord(char) - shift if char.islower(): if shifted < ord('a'): shifted += 26 elif char.isupper(): if shifted < ord('A'): shifted += 26 decrypted_text += chr(shifted) else: decrypted_text += char return decrypted_text def remove_special_char(text): special_chars = "!@#$%^&*()-_=+[]{}|;':\",.<>/?" cleaned_text = "" for char in text: if char not in special_chars: cleaned_text += char return cleaned_text def multi_round_decrypt(text, shifts): decrypted_text = text for shift in reversed(shifts): decrypted_text = remove_special_char(decrypted_text) decrypted_text = caesar_cipher_decrypt(decrypted_text, shift) return decrypted_text if __name__ == "__main__": encrypted_text = input("请输入要解密的文本:") shifts = [int(input("请输入第{}轮的偏移量:".format(i+1))) for i in range(3)] decrypted_text = multi_round_decrypt(encrypted_text, shifts) print("解密后的文本:", decrypted_text)