You are on page 1of 2

Worksheet 1

Student Name: MIHIR GARG UID:19BCS1384


Branch: CSE Section/Group: 19BCS_IS_5A
Semester: 6th Date of Performance: -
Subject Name: Information Security Lab Subject Code: CSB-372

Aim  Code to implement Caesar cipher

Code 



def encryptPlainText(plainText,s):
result = ""
for i in range(len(plainText)):
ch = plainText[i]
if (ch.isupper()):
v = (ord(ch) + s - 65) % 26
result += chr(v+65)
else:
v = (ord(ch) + s - 97) % 26
result += chr(v+97)
return result

def decryptCaeserText(plainText,s):
s=26-s
result1 = ""
for i in range(len(plainText)):
ch = plainText[i]
if (ch.isupper()):
v = (ord(ch) + s - 65) % 26
result1 += chr(v+65)
else:
v = (ord(ch) + s - 97) % 26
result1 += chr(v+97)
return result1

str1=input("Enter the text you want to encypt --> ")


valShift=input("Enter the number of character you want to shift --> ")
print("Plain Text : " + str1)
print("Shift Character : " + str(valShift))
print("CaeserCipher Text: " + encryptPlainText(str1,int(valShift)))
print("Decrpyt CaserCipher Text: " +
decryptCaeserText(encryptPlainText(str1,int(valShift)),int(valShift)))




Output 

You might also like