-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaconianCipher.py
74 lines (71 loc) · 1.59 KB
/
BaconianCipher.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def encrypt(pt):
baconian = {
'A': "aaaaa",
'B': "aaaab",
'C': "aaaba",
'D': "aaabb",
'E': "aabaa",
'F': "aabab",
'G': "aabba",
'H': "aabbb",
'I': "abaaa",
'J': "abaab",
'K': "ababa",
'L': "ababb",
'M': "abbaa",
'N': "abbab",
'O': "abbba",
'P': "abbbb",
'Q': "baaaa",
'R': "baaab",
'S': "baaba",
'T': "baabb",
'U': "babaa",
'V': "babab",
'W': "babba",
'X': "babbb",
'Y': "bbaaa",
'Z': "bbaab"
}
encpt1=""
for i in range(0,len(pt)):
encpt1 = encpt1 + baconian[pt[i]]
return encpt1
def decrypt(encpt):
baconian = {
"aaaaa":"A",
"aaaab":"B",
"aaaba":"C",
"aaabb":"D",
"aabaa":"E",
"aabab":"F",
"aabba":"G",
"aabbb":"H",
"abaaa":"I",
"abaab":"J",
"ababa":"K",
"ababb":"L",
"abbaa":"M",
"abbab":"N",
"abbba":"O",
"abbbb":"P",
"baaaa":"Q",
"baaab":"R",
"baaba":"S",
"baabb":"T",
"babaa":"U",
"babab":"V",
"babba":"W",
"babbb":"X",
"bbaaa":"Y",
"bbaab":"Z"
}
decpt1 = ""
for i in range(0,len(encpt),5):
decpt1 = decpt1 + baconian[encpt[i:i+5]]
return decpt1
pt=input("Enter plaintext: ")
encpt=encrypt(pt)
print("Encrypted text: ",encpt)
decpt=decrypt(encpt)
print("Decrypted text: ",decpt)