-
Notifications
You must be signed in to change notification settings - Fork 0
/
devanagari.py
52 lines (41 loc) · 1.54 KB
/
devanagari.py
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
from random import shuffle
chars=["क","ख","ग","घ","ङ","च","छ","ज","झ","ण","त","थ","द","ध","न","प","फ","ब","भ","म","य","र","ल","व","स","श","ष","ह","ञ"]
symbols=["ै","ौ","ृ","ु","ू","ि","ी","ो","ा","े"]
#maps for chars
keys=list(chars)
shuffled_keys=list(chars)
shuffle(shuffled_keys)
#Maps for Symbols
keys_symbols=list(symbols)
shuffled_keys_symbols=list(symbols)
shuffle(shuffled_keys_symbols)
#dict for maps
maps=dict(zip(keys,shuffled_keys))
reversed_maps=dict(zip(shuffled_keys,keys))
#dict for symbols maps
maps_symbols=dict(zip(keys_symbols,shuffled_keys_symbols))
reversed_maps_symbols=dict(zip(shuffled_keys_symbols,keys_symbols))
def encrypt(message):
cipher=[]
for letters in message:
if letters in chars:
cipher_letters=maps[letters]
cipher.append(cipher_letters)
elif letters in symbols:
cipher_symbols=maps_symbols[letters]
cipher.append(cipher_symbols)
return "".join(cipher)
def decrypt(ciphers):
plaintext=[]
for letters in ciphers:
if letters in chars:
plaintext_letters=reversed_maps[letters]
plaintext.append(plaintext_letters)
elif letters in symbols:
plaintext_symbols=reversed_maps_symbols[letters]
plaintext.append(plaintext_symbols)
return " ".join(plaintext)
a=encrypt("मेरोदेशनेपालहो")
print("Encrypted Letters is: ",a)
b=decrypt(a)
print("Decrypted Letters is:",b)