Saturday, 22 January 2022

Python-slip14b-Write a Python program to display plain text and cipher text using a Caesar encryption.

Write a Python program to display plain text and cipher text using a Caesar encryption.

def encrypt(string, shift):

   cipher = ''

  for char in string:

    if char == ' ':

      cipher = cipher + char

    elif  char.isupper():

      cipher = cipher + chr((ord(char) + shift - 65) % 26 + 65)

    else:

      cipher = cipher + chr((ord(char) + shift - 97) % 26 + 97)

 

  return cipher

 

text = input("enter string: ")

s = int(input("enter shift number: "))

print("original string: ", text)

print("after encryption: ", encrypt(text, s))