Skip to content

Commit 185db23

Browse files
authored
Create Encryptio-python-code.py
1 parent 77eeae7 commit 185db23

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Encryptio-python-code.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Create a function for Encryption algorithm
2+
def encrpyt_message(text, key):
3+
encrypted_msg = "" # initially empty string is created
4+
for char in text:
5+
6+
if char.isupper(): # check character is uppercase
7+
encrypted_msg += chr((((ord(char) + key) -65) % 26) + 65)
8+
9+
elif char.islower(): # checks character is lowercase
10+
encrypted_msg += chr((((ord(char) + key) -97) % 26) + 97)
11+
12+
else:
13+
encrypted_msg += char # Numbers, spaces and characters are added as it is.
14+
15+
return encrypted_msg

0 commit comments

Comments
 (0)