Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions caesar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ def encrypt(s): # Function for encrypting the text
print('\nEncrypted text output :', end=' ')
for x in s: # Repeating the loop for each character in the string
if x.isalpha(): # Check if the chracter is an alphabet (irrespective of the case)
var = ord(x) # If True, then process the ASCII value of the shifted character
var += n
var = n + ord(x) # If True, then process the ASCII value of the shifted character
if var > 90:
var -= 26

if var < 65:
elif var < 65:
var += 26

print(chr(var), end='') # And print the shifted character
else:
print(x, end='') # Else print the character as it is
Expand All @@ -27,11 +24,10 @@ def decrypt(s): # Function for decrypting the text
print('\nDecrypted text output :', end=' ')
for x in s: # Repeating the loop for each character in the string
if x.isalpha(): # Check if the chracter is an alphabet (irrespective of the case)
var = ord(x) # If True, then process the ASCII value of the shifted character
var -= n
var = ord(x)-n # If True, then process the ASCII value of the shifted character
if var > 90:
var -= 26
if var < 65:
elif var < 65:
var += 26

print(chr(var), end='') # And print the shifted character
Expand Down