Implementation of Caesar password by python

topic description

Caesar cipher is an algorithm used by Julius Caesar in ancient Rome to encrypt and decrypt military information. it uses a replacement method to cycle every English character in the message with the third character after that character in the alphabet sequence, that is, the correspondence of the alphabet is as follows:

original: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
ciphertext: D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
for the original character P, the ciphertext character C satisfies the following conditions: C = (pendant 3) mod 26
above is the encryption method of Caesar cipher, and vice versa. That is: P = (C Mel 3) mod 26
assuming that the input that the user may use contains only lowercase letters aquiz and spaces, please write a program to encrypt the input string with Caesar cipher and directly output the result, where the spaces do not need to be encrypted

sources of topics and their own ideas

my idea is that letters-"get subscript numbers -" calculate ciphertext-"convert to letters

"

related codes

pList=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
p=input().upper()
arr=[]
arr1=[]
arr2=[]
arr3=[]
arr4=[]
for i in range(len(p)):
    if p[i] in pList:
        arr.append(p[i])
print(arr)
for j in range(len(arr)):
    charIndex=pList.index(arr[j])
    arr1.append(charIndex)
for k in range(len(arr1)):
    c=(arr1[k]+3)%26
    arr2.append(c)
for i in range(len(arr2)):
    for j in range(len(pList)):
        if arr2[i]==j:
            arr3.append(pList[j])
print(arr3)
str=""
for i in range(len(p)):
    if p[i]==" ":
        print(i)
        arr4.append(i)
print(arr4)
for j in range(len(arr4)):
    str1=str.join(arr3)
print("{}".format(str.join(arr3).lower()))

what result do you expect? What is the error message actually seen?

error message: the space cannot be processed to add

when it is finally converted to letters.

clipboard.png

May.09,2021

obviously Caesar transposition cipher does not deal with spaces, just add a judgment


with regard to Caesar's password, this is how I implement it:

if __name__ == "__main__":
    p = input().upper()
    o = []
    for i in list(p):
        if i is not " ": 
            c = ord(i)+3
            if c > ord("Z"):
                c -= 26
            o.append(chr(c).lower())
        else:
            o.append(" ")
    
    out = ''.join(o)
    print(out)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37195-2c04b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37195-2c04b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?