凯撒密码用python编程。

A Caesar cipher is a simple substitution cipher based on the idea of shifting each letter of the plaintext
message a fixed number (called the key) of positions in the alphabet. For example, if the key value is
2, the word “Sourpuss” would be encoded as “Uqwtrwuu.” The original message can be recovered by
“reencoding” it using the negative of the key.
Write a program that can encode and decode Caesar ciphers. The input to the program will be a string
of plaintext and the value of the key. The output will be an encoded message where each character in
the original message is replaced by shifting it key characters in the ASCII character set. For example,
if ch is a character in the string and key is the amount to shift, then the character that replaces ch can
be calculated as: chr(ord(ch) + key).

很急啊。求大神。
最新回答
汏姐萌神

2024-11-02 18:12:01

参考一下C语言的,也许有帮助:
http://hi.baidu.com/%D7%F6%B6%F8%C2%DB%B5%C0/blog/item/1e255c50824ae0968d5430eb.html

http://hi.baidu.com/%D7%F6%B6%F8%C2%DB%B5%C0/blog/item/b62441fa541839294f4aea9f.html
送舟行

2024-11-02 03:06:58

def caesar_cipher(s, key=2):
return ''.join((chr(ord(ch) + key) for ch in s))