【精选】【Python 您所在的位置:网站首页 凯撒密码加密例题 【精选】【Python

【精选】【Python

2023-10-21 07:53| 来源: 网络整理| 查看: 265

一、实验项目名称(实验题目): 凯撒加密法 二、实验目的与要求: 掌握凯撒加密法的原理和步骤,掌握for循环的使用。 三、实验内容: 1、运行凯撒加密法程序。

# Caesar Cipher # http://inventwithpython.com/hacking (BSD Licensed) import pyperclip # the string to be encrypted/decrypted message = 'This is my secret message.' # the encryption/decryption key key = 13 # tells the program to encrypt or decrypt mode = 'encrypt' # set to 'encrypt' or 'decrypt' # every possible symbol that can be encrypted LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' # stores the encrypted/decrypted form of the message translated = '' # capitalize the string in message message = message.upper() # run the encryption/decryption code on each symbol in the message string for symbol in message: if symbol in LETTERS: # get the encrypted (or decrypted) number for this symbol num = LETTERS.find(symbol) # get the number of the symbol if mode == 'encrypt': num = num + key elif mode == 'decrypt': num = num - key # handle the wrap-around if num is larger than the length of # LETTERS or less than 0 if num >= len(LETTERS): num = num - len(LETTERS) elif num


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有