-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalphabetic_cipher.py
319 lines (306 loc) · 7.85 KB
/
alphabetic_cipher.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# -*- coding: utf-8 -*-
"""
Authored by Charles Thomas Wallace Truscott Watters, two days before Christmas 2022
runfile('C:/Users/Charles/Documents/alphabetic_cipher.py', wdir='C:/Users/Charles/Documents')
[('a', 0), ('b', 1), ('c', 2), ('d', 3), ('e', 4), ('f', 5), ('g', 6), ('h', 7), ('i', 8), ('j', 9), ('k', 10), ('l', 11), ('m', 12), ('n', 13), ('o', 14), ('p', 15), ('q', 16), ('r', 17), ('s', 18), ('t', 19), ('u', 20), ('v', 21), ('w', 22), ('x', 23), ('y', 24), ('z', 25), ('A', 26), ('B', 27), ('C', 28), ('D', 29), ('E', 30), ('F', 31), ('G', 32), ('H', 33), ('I', 34), ('J', 35), ('K', 36), ('L', 37), ('M', 38), ('N', 39), ('O', 40), ('P', 41), ('Q', 42), ('R', 43), ('S', 44), ('T', 45), ('U', 46), ('V', 47), ('W', 48), ('X', 49), ('Y', 50), ('Z', 51), (' ', 52), ('~', 53), ('!', 54), ('@', 55), ('#', 56), ('$', 57), ('%', 58), ('^', 59), ('&', 60), ('*', 61), ('(', 62), (')', 63), ('_', 64), ('-', 65), ('+', 66), ('=', 67), ('{', 68), ('}', 69), ('|', 70), ('\\', 71), (':', 72), (';', 73), ('"', 74), ("'", 75), (',', 76), ('<', 77), ('>', 78), ('.', 79), ('?', 80), ('/', 81)]
0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111
10000
10001
10010
10011
10100
10101
10110
10111
11000
11001
11010
11011
11100
11101
11110
11111
100000
100001
100010
100011
100100
100101
100110
100111
101000
101001
101010
101011
101100
101101
101110
101111
110000
110001
110010
110011
110100
110101
110110
110111
111000
111001
111010
111011
111100
111101
111110
111111
1000000
1000001
1000010
1000011
1000100
1000101
1000110
1000111
1001000
1001001
1001010
1001011
1001100
1001101
1001110
1001111
1010000
1010001
11100
111
0
10001
1011
100
10010
110100
101101
111
1110
1100
0
10010
110100
110000
0
1011
1011
0
10
100
110100
101101
10001
10100
10010
10
1110
10011
10011
1001111
110100
100110
0
10001
1010
110100
110000
1000
1011
1011
1000
0
1100
110100
110000
0
10011
10011
100
10001
10010
1001111
110100
101001
1011
0
1000
1101
10011
100
10111
10011
110100
101
1110
10001
110100
10
10001
11000
1111
10011
1110
110
10001
0
1111
111
11000
[28, 7, 0, 17, 11, 4, 18, 52, 45, 7, 14, 12, 0, 18, 52, 48, 0, 11, 11, 0, 2, 4, 52, 45, 17, 20, 18, 2, 14, 19, 19, 79, 52, 38, 0, 17, 10, 52, 48, 8, 11, 11, 8, 0, 12, 52, 48, 0, 19, 19, 4, 17, 18, 79, 52, 41, 11, 0, 8, 13, 19, 4, 23, 19, 52, 5, 14, 17, 52, 2, 17, 24, 15, 19, 14, 6, 17, 0, 15, 7, 24]
The trinary representation of the ciphertext is:
00000000000001001
00000000000000021
00000000000000000
00000000000000122
00000000000000102
00000000000000011
00000000000000200
00000000000001221
00000000000001200
00000000000000021
00000000000000112
00000000000000110
00000000000000000
00000000000000200
00000000000001221
00000000000001210
00000000000000000
00000000000000102
00000000000000102
00000000000000000
00000000000000002
00000000000000011
00000000000001221
00000000000001200
00000000000000122
00000000000000202
00000000000000200
00000000000000002
00000000000000112
00000000000000201
00000000000000201
00000000000002221
00000000000001221
00000000000001102
00000000000000000
00000000000000122
00000000000000101
00000000000001221
00000000000001210
00000000000000022
00000000000000102
00000000000000102
00000000000000022
00000000000000000
00000000000000110
00000000000001221
00000000000001210
00000000000000000
00000000000000201
00000000000000201
00000000000000011
00000000000000122
00000000000000200
00000000000002221
00000000000001221
00000000000001112
00000000000000102
00000000000000000
00000000000000022
00000000000000111
00000000000000201
00000000000000011
00000000000000212
00000000000000201
00000000000001221
00000000000000012
00000000000000112
00000000000000122
00000000000001221
00000000000000002
00000000000000122
00000000000000220
00000000000000120
00000000000000201
00000000000000112
00000000000000020
00000000000000122
00000000000000000
00000000000000120
00000000000000021
00000000000000220
"""
def trinary_repr(integer):
tristr = ''
# for x in range(integer, 0, -1):
for n in range(16, -1, -1):
# print("n: {}, integer: {}".format(n, integer))
if (integer // ( 2 * (3 ** n))) == 1:
tristr += '2'
integer -= 2 * (3 ** n)
continue
if integer // 3 ** n == 1:
tristr += '1'
integer -= 3 ** n
continue
else:
tristr += '0'
continue
# if integer / 2 == 1:
# tristr += '2'
# integer -= 2
# elif integer / 1 == 1:
# tristr += '1'
# integer -= 1
print(tristr)
return tristr
def binary_repr(integer):
return bin(integer)
def binary_print(integer):
print("{:16b}".format(integer))
pass
def main():
alphabet_lower = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z")
alphabet_upper = ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
space = tuple(" ")
punctuation = ("~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "-", "+", "=", "{", "}", "|", "\\", ":", ";", "\"", "\'", ",", "<", ">", ".", "?", "/")
L = list(alphabet_lower + alphabet_upper + space + punctuation)
index = list(x for x in range(len(L)))
charset_plain = list(zip(L, index))
print(charset_plain)
for x in charset_plain:
binary_print(x[1])
plaintext = "Charles Thomas Wallace Truscott. Mark William Watters. Plaintext for cryptography"
numbertext = []
for x in plaintext:
for y in charset_plain:
if y[0] == x:
numbertext.append(y[1])
break
for number in numbertext:
binary_print(number)
print(numbertext)
print("The trinary representation of the ciphertext is: ")
for number in numbertext:
trinary_repr(number)
if __name__ == "__main__": main()