Caesar password python code

Caesar password python code

Xiaobai wrote it casually, the most stupid way

Question: Caesar
Cipher
‬Description
Caesar Cipher is an algorithm used by the Roman Emperor Caesar to encrypt and decrypt military intelligence. It uses a replacement method to cyclically replace each English character in the message with the third character after the character in the alphabet sequence , That is, the correspondence relationship of the alphabet is as follows: ‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‬‬‪‬‬‬‬‬‬‪‬‬‬‪ original:
ABCDEFGHIJKLMNOPQRSTU VWXYZ ‮‬‫‬‪‬

Ciphertext: DEFGHIJKLMNOPQRSTUVWX YZABC for
the original character P, the character ciphertext C which satisfy the following conditions: C = (P + 3) mod 26 the above
is Caesar cipher encryption method, decryption method and vice versa, i.e.: P = (C-3) mod 26 ‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‬‬‬‬‬‬‬‬‬‬‬‬‬

Assuming that the input that the user may use contains uppercase and lowercase letters a zA Z, spaces and special symbols, please write a program to encrypt the input string with the Caesar password, and directly output the result, where the spaces do not need to be encrypted. Use input() to get input.
input
example 1: python is good
output
example 1: sbwkrq lv jrrg

Caesar password encryption:

#凯撒密码加密
P = input()
ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
CBA = "DEFGHIJKLMNOPQRSTUVWXYZABCdefghijklmnopqrstuvwxyzabc"
u = len(P)
for i in range(u):
    s = P[i]
    if s in ABC:
        n=ABC.index(s)
        print(CBA[n],end='')
    else:
        print(s,end='')

Caesar password decryption:

#凯撒密码解密
P = input()
ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
CBA = "DEFGHIJKLMNOPQRSTUVWXYZABCdefghijklmnopqrstuvwxyzabc"
u = len(P)
for i in range(u):
    s = P[i]
    if s in CBA:
        n=CBA.index(s)
        print(ABC[n],end='')
    else:
        print(s,end='')

Guess you like

Origin blog.csdn.net/weixin_44634558/article/details/108776715