-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyJSEnDeCrypt.py
More file actions
61 lines (38 loc) · 1.41 KB
/
PyJSEnDeCrypt.py
File metadata and controls
61 lines (38 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# ---------------------------------------------------------------------------------------------- #
# PyJSEnDeCypt : Based upon famour Caesar cipher to encrypt or decrpt messages
#
# This script takes input messages to encrypt and then using the same key you
# can decrypt the message
# ---------------------------------------------------------------------------------------------- #
def js_encrypt():
global alphabets
alphabets='abcdefghijklmnopqrstuvwxyz'
usr_msg=input('Type your message to encrypt: ')
key=input('Provide us your secret key : ' )
enc_string=''
casted_usr_msg=str(usr_msg)
key=int(key)
for val in casted_usr_msg:
if val in alphabets:
position=int(alphabets.find(val))
enc_position=(position+key) % 26
enc_string+=alphabets[enc_position]
else:
enc_string+=val
print(enc_string)
def js_decrypt():
usr_msg=input('Type or copy paste your encrypted message to descrypt: ')
key=input('Input us your provided secret key : ' )
dec_string=''
casted_usr_msg=str(usr_msg)
key=int(key)
for val in casted_usr_msg:
if val in alphabets:
position=int(alphabets.find(val))
dec_position=(position-key) % 26
dec_string+=alphabets[dec_position]
else:
dec_string+=val
print(dec_string)
js_encrypt()
js_decrypt()