1. Caesar Encryption
Caesar encrypts messages by shifting, with a maximum of 25 encryption methods (24 at the beginning, since the letters were 25)
For example, the plaintext ' I love ' shift 2-bit encrypted dark text is ' K nqxg ejkpc ' 2. Code implementation
def change (c,i):
C = c.lower ()
num = Ord (c)
if Num >= and num <= 122:
num = ((num-97) + i) % return
chr (num)
def kaisa_jiami (string,i):
string_new = "for
s in string:
string_new + = Chang E (s,i)
print (string_new) return
string_new
def kaisa_jiemi (string): To
I in range (
a): Print (' \ n ', I, ' \ n ')
i + + 1
kaisa_jiami (string,i)
def main ():
print (' Select the action you want: ')
print (' 1: Caesar encryption ')
print (' 2: Caesar decryption ')
choice = input ()
if choice = = ' 1 ':
string = input (' Enter the string to be encrypted: ')
num = Int (input (' Please enter the number of digits to be offset: '))
Kaisa_jiami (string,num)
elif Choice = = ' 2 ':
string = input (' Please enter the string you want to decrypt: ')
Kaisa_jiemi (String)
else:
print (' input error, please try again. ')
main ()
if __name__ = = ' __main__ ':
Main ()
3. Effect
Encryption:
decryption:
Find the correct plaintext: