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.