Question
Encrypt and decrypt cryptography in Python? The code I got: def encrypt(text): result = s = 3 # traverse text for i in range(len(text)):
Encrypt and decrypt cryptography in Python?
The code I got:
def encrypt(text): result = "" s = 3 # traverse text 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
def decrypt(text): result = "" s = 26-3 # traverse text for i in range(len(text)): char = text[i]
# Decrypt uppercase characters if (char.isupper()): result += chr((ord(char) + s-65) % 26 + 65)
# Decrypt lowercase characters else: result += chr((ord(char) + s - 97) % 26 + 97)
return result
#check the above function text = input("Enter Message Please:")
print("Text : " + text) cipher = encrypt(text) print("Cipher: " + cipher) print("De-Cipher: " + decrypt(cipher))
OUTPUT:
Enter Message Please: Hello People! Text : Hello People! Cipher: KhoorqShrsohr De-Cipher: HellonPeopleo
How do I modify this code to get the following output:
Enter Message Please: Hello People! Text : Hello People! Cipher: Khoorq Shrsohr! De-Cipher: Hello People!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started