forked from kal179/Beginners_Python_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesarsCipher.py
More file actions
18 lines (14 loc) · 759 Bytes
/
caesarsCipher.py
File metadata and controls
18 lines (14 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
getToEncrypt = str(input('Message to encrypt : ')) # string to encrypt
key = int(input('Key for encryption : ')) # key of cipher for encryption
def cipher(message):
for x in message:
prepare = ord(x) # returns ascii value of character
prepareMore = chr(prepare + key) # chr() returns character from ascii value
return(str(prepareMore)) # returning value
final = list(map(cipher, getToEncrypt)) # converting message into list of elements
def concatenateElements(dogs):
result= ''
for element in dogs:
result += str(element)
return('Encrypted message is : ' + result) # unpacking list and concatenating its elements
print(concatenateElements(final)) # printing elements