You are on page 1of 3

Cryptography and System Security Lab File ( TE SEM VI Computer Engineering)

Roll No : 2103149
Batch : C31
Name : Rittika Rijhwani
EXPERIMENT 2

Aim: To implement Caesar cipher

CODE:

def encrypt(text,s):
result = ""
for i in range(len(text)):
char = text[i]

# Encrypt uppercase characters


if (char.isupper()):
result += chr((ord(char) + s-65) % 26 + 65)

# Encrypt lowercase characters


else:
result += chr((ord(char) + s - 97) % 26 + 97)

return result

text = input("Enter text to encrypt: ")


s = int(input("Shift value: "))
print ("Text : " + text)
print ("Shift : " + str(s))
print ("Cipher: " + encrypt(text,s))

OUTPUT:

Enter text to encrypt: RITTIKA


Shift value: 3
Text : RITTIKA
Shift : 3
Cipher: ULWWLND

You might also like