-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
382 lines (307 loc) · 19.2 KB
/
main.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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# для нелинейного биективного (S)
# в 10 виде
# pi = (252, 238, 221, 17, 207, 110, 49, 22, 251, 196, 250, 218, 35, 197, 4, 77, 233, 119, 240,
# 219, 147, 46, 153, 186, 23, 54, 241, 187, 20, 205, 95, 193, 249, 24, 101, 90, 226, 92, 239,
# 33, 129, 28, 60, 66, 139, 1, 142, 79, 5, 132, 2, 174, 227, 106, 143, 160, 6, 11, 237, 152, 127,
# 212, 211, 31, 235, 52, 44, 81, 234, 200, 72, 171, 242, 42, 104, 162, 253, 58, 206, 204, 181,
# 112, 14, 86, 8, 12, 118, 18, 191, 114, 19, 71, 156, 183, 93, 135, 21, 161, 150, 41, 16, 123,
# 154, 199, 243, 145, 120, 111, 157, 158, 178, 177, 50, 117, 25, 61, 255, 53, 138, 126, 109,
# 84, 198, 128, 195, 189, 13, 87, 223, 245, 36, 169, 62, 168, 67, 201, 215, 121, 214, 246, 124,
# 34, 185, 3, 224, 15, 236, 222, 122, 148, 176, 188, 220, 232, 40, 80, 78, 51, 10, 74, 167, 151,
# 96, 115, 30, 0, 98, 68, 26, 184, 56, 130, 100, 159, 38, 65, 173, 69, 70, 146, 39, 94, 85, 47,
# 140, 163, 165, 125, 105, 213, 149, 59, 7, 88, 179, 64, 134, 172, 29, 247, 48, 55, 107, 228,
# 136, 217, 231, 137, 225, 27, 131, 73, 76, 63, 248, 254, 141, 83, 170, 144, 202, 216, 133, 97,
# 32, 113, 103, 164, 45, 43, 9, 91, 203, 155, 37, 208, 190, 229, 108, 82, 89, 166, 116, 210,
# 230, 244, 180, 192, 209, 102, 175, 194, 57, 75, 99, 182)
# в 16 виде
# Pi = [0xFC, 0xEE, 0xDD, 0x11, 0xCF, 0x6E, 0x31, 0x16, 0xFB, 0xC4, 0xFA, 0xDA, 0x23, 0xC5, 0x04, 0x4D,
# 0xE9, 0x77, 0xF0, 0xDB, 0x93, 0x2E, 0x99, 0xBA, 0x17, 0x36, 0xF1, 0xBB, 0x14, 0xCD, 0x5F, 0xC1,
# 0xF9, 0x18, 0x65, 0x5A, 0xE2, 0x5C, 0xEF, 0x21, 0x81, 0x1C, 0x3C, 0x42, 0x8B, 0x01, 0x8E, 0x4F,
# 0x05, 0x84, 0x02, 0xAE, 0xE3, 0x6A, 0x8F, 0xA0, 0x06, 0x0B, 0xED, 0x98, 0x7F, 0xD4, 0xD3, 0x1F,
# 0xEB, 0x34, 0x2C, 0x51, 0xEA, 0xC8, 0x48, 0xAB, 0xF2, 0x2A, 0x68, 0xA2, 0xFD, 0x3A, 0xCE, 0xCC,
# 0xB5, 0x70, 0x0E, 0x56, 0x08, 0x0C, 0x76, 0x12, 0xBF, 0x72, 0x13, 0x47, 0x9C, 0xB7, 0x5D, 0x87,
# 0x15, 0xA1, 0x96, 0x29, 0x10, 0x7B, 0x9A, 0xC7, 0xF3, 0x91, 0x78, 0x6F, 0x9D, 0x9E, 0xB2, 0xB1,
# 0x32, 0x75, 0x19, 0x3D, 0xFF, 0x35, 0x8A, 0x7E, 0x6D, 0x54, 0xC6, 0x80, 0xC3, 0xBD, 0x0D, 0x57,
# 0xDF, 0xF5, 0x24, 0xA9, 0x3E, 0xA8, 0x43, 0xC9, 0xD7, 0x79, 0xD6, 0xF6, 0x7C, 0x22, 0xB9, 0x03,
# 0xE0, 0x0F, 0xEC, 0xDE, 0x7A, 0x94, 0xB0, 0xBC, 0xDC, 0xE8, 0x28, 0x50, 0x4E, 0x33, 0x0A, 0x4A,
# 0xA7, 0x97, 0x60, 0x73, 0x1E, 0x00, 0x62, 0x44, 0x1A, 0xB8, 0x38, 0x82, 0x64, 0x9F, 0x26, 0x41,
# 0xAD, 0x45, 0x46, 0x92, 0x27, 0x5E, 0x55, 0x2F, 0x8C, 0xA3, 0xA5, 0x7D, 0x69, 0xD5, 0x95, 0x3B,
# 0x07, 0x58, 0xB3, 0x40, 0x86, 0xAC, 0x1D, 0xF7, 0x30, 0x37, 0x6B, 0xE4, 0x88, 0xD9, 0xE7, 0x89,
# 0xE1, 0x1B, 0x83, 0x49, 0x4C, 0x3F, 0xF8, 0xFE, 0x8D, 0x53, 0xAA, 0x90, 0xCA, 0xD8, 0x85, 0x61,
# 0x20, 0x71, 0x67, 0xA4, 0x2D, 0x2B, 0x09, 0x5B, 0xCB, 0x9B, 0x25, 0xD0, 0xBE, 0xE5, 0x6C, 0x52,
# 0x59, 0xA6, 0x74, 0xD2, 0xE6, 0xF4, 0xB4, 0xC0, 0xD1, 0x66, 0xAF, 0xC2, 0x39, 0x4B, 0x63, 0xB6]
# в бинарном виде
pi_bin = ['11111100', '11101110', '11011101', '00010001', '11001111', '01101110', '00110001', '00010110', '11111011',
'11000100', '11111010', '11011010', '00100011', '11000101', '00000100', '01001101', '11101001', '01110111',
'11110000', '11011011', '10010011', '00101110', '10011001', '10111010', '00010111', '00110110', '11110001',
'10111011', '00010100', '11001101', '01011111', '11000001', '11111001', '00011000', '01100101', '01011010',
'11100010', '01011100', '11101111', '00100001', '10000001', '00011100', '00111100', '01000010', '10001011',
'00000001', '10001110', '01001111', '00000101', '10000100', '00000010', '10101110', '11100011', '01101010',
'10001111', '10100000', '00000110', '00001011', '11101101', '10011000', '01111111', '11010100', '11010011',
'00011111', '11101011', '00110100', '00101100', '01010001', '11101010', '11001000', '01001000', '10101011',
'11110010', '00101010', '01101000', '10100010', '11111101', '00111010', '11001110', '11001100', '10110101',
'01110000', '00001110', '01010110', '00001000', '00001100', '01110110', '00010010', '10111111', '01110010',
'00010011', '01000111', '10011100', '10110111', '01011101', '10000111', '00010101', '10100001', '10010110',
'00101001', '00010000', '01111011', '10011010', '11000111', '11110011', '10010001', '01111000', '01101111',
'10011101', '10011110', '10110010', '10110001', '00110010', '01110101', '00011001', '00111101', '11111111',
'00110101', '10001010', '01111110', '01101101', '01010100', '11000110', '10000000', '11000011', '10111101',
'00001101', '01010111', '11011111', '11110101', '00100100', '10101001', '00111110', '10101000', '01000011',
'11001001', '11010111', '01111001', '11010110', '11110110', '01111100', '00100010', '10111001', '00000011',
'11100000', '00001111', '11101100', '11011110', '01111010', '10010100', '10110000', '10111100', '11011100',
'11101000', '00101000', '01010000', '01001110', '00110011', '00001010', '01001010', '10100111', '10010111',
'01100000', '01110011', '00011110', '00000000', '01100010', '01000100', '00011010', '10111000', '00111000',
'10000010', '01100100', '10011111', '00100110', '01000001', '10101101', '01000101', '01000110', '10010010',
'00100111', '01011110', '01010101', '00101111', '10001100', '10100011', '10100101', '01111101', '01101001',
'11010101', '10010101', '00111011', '00000111', '01011000', '10110011', '01000000', '10000110', '10101100',
'00011101', '11110111', '00110000', '00110111', '01101011', '11100100', '10001000', '11011001', '11100111',
'10001001', '11100001', '00011011', '10000011', '01001001', '01001100', '00111111', '11111000', '11111110',
'10001101', '01010011', '10101010', '10010000', '11001010', '11011000', '10000101', '01100001', '00100000',
'01110001', '01100111', '10100100', '00101101', '00101011', '00001001', '01011011', '11001011', '10011011',
'00100101', '11010000', '10111110', '11100101', '01101100', '01010010', '01011001', '10100110', '01110100',
'11010010', '11100110', '11110100', '10110100', '11000000', '11010001', '01100110', '10101111', '11000010',
'00111001', '01001011', '01100011', '10110110']
# Для перестановок (P)
tau = (0, 8, 16, 24, 32, 40, 48, 56, 1, 9, 17, 25, 33, 41, 49, 57, 2, 10, 18, 26, 34, 42, 50, 58,
3, 11, 19, 27, 35, 43, 51, 59, 4, 12, 20, 28, 36, 44, 52, 60, 5, 13, 21, 29, 37, 45, 53, 61, 6, 14,
22, 30, 38, 46, 54, 62, 7, 15, 23, 31, 39, 47, 55, 63)
# для линейного (L)
matrix_A = ["8e20faa72ba0b470", "47107ddd9b505a38", "ad08b0e0c3282d1c", "d8045870ef14980e",
"6c022c38f90a4c07", "3601161cf205268d", "1b8e0b0e798c13c8", "83478b07b2468764",
"a011d380818e8f40", "5086e740ce47c920", "2843fd2067adea10", "14aff010bdd87508",
"0ad97808d06cb404", "05e23c0468365a02", "8c711e02341b2d01", "46b60f011a83988e",
"90dab52a387ae76f", "486dd4151c3dfdb9", "24b86a840e90f0d2", "125c354207487869",
"092e94218d243cba", "8a174a9ec8121e5d", "4585254f64090fa0", "accc9ca9328a8950",
"9d4df05d5f661451", "c0a878a0a1330aa6", "60543c50de970553", "302a1e286fc58ca7",
"18150f14b9ec46dd", "0c84890ad27623e0", "0642ca05693b9f70", "0321658cba93c138",
"86275df09ce8aaa8", "439da0784e745554", "afc0503c273aa42a", "d960281e9d1d5215",
"e230140fc0802984", "71180a8960409a42", "b60c05ca30204d21", "5b068c651810a89e",
"456c34887a3805b9", "ac361a443d1c8cd2", "561b0d22900e4669", "2b838811480723ba",
"9bcf4486248d9f5d", "c3e9224312c8c1a0", "effa11af0964ee50", "f97d86d98a327728",
"e4fa2054a80b329c", "727d102a548b194e", "39b008152acb8227", "9258048415eb419d",
"492c024284fbaec0", "aa16012142f35760", "550b8e9e21f7a530", "a48b474f9ef5dc18",
"70a6a56e2440598e", "3853dc371220a247", "1ca76e95091051ad", "0edd37c48a08a6d8",
"07e095624504536c", "8d70c431ac02a736", "c83862965601dd1b", "641c314b2b8ee083"]
# набор констант для KeySchedule
C = [
"b1085bda1ecadae9ebcb2f81c0657c1f2f6a76432e45d016714eb88d7585c4fc4b7ce09192676901a2422a08a460d31505767436cc744d23dd806559f2a64507",
"6fa3b58aa99d2f1a4fe39d460f70b5d7f3feea720a232b9861d55e0f16b501319ab5176b12d699585cb561c2db0aa7ca55dda21bd7cbcd56e679047021b19bb7",
"f574dcac2bce2fc70a39fc286a3d843506f15e5f529c1f8bf2ea7514b1297b7bd3e20fe490359eb1c1c93a376062db09c2b6f443867adb31991e96f50aba0ab2",
"ef1fdfb3e81566d2f948e1a05d71e4dd488e857e335c3c7d9d721cad685e353fa9d72c82ed03d675d8b71333935203be3453eaa193e837f1220cbebc84e3d12e",
"4bea6bacad4747999a3f410c6ca923637f151c1f1686104a359e35d7800fffbdbfcd1747253af5a3dfff00b723271a167a56a27ea9ea63f5601758fd7c6cfe57",
"ae4faeae1d3ad3d96fa4c33b7a3039c02d66c4f95142a46c187f9ab49af08ec6cffaa6b71c9ab7b40af21f66c2bec6b6bf71c57236904f35fa68407a46647d6e",
"f4c70e16eeaac5ec51ac86febf240954399ec6c7e6bf87c9d3473e33197a93c90992abc52d822c3706476983284a05043517454ca23c4af38886564d3a14d493",
"9b1f5b424d93c9a703e7aa020c6e41414eb7f8719c36de1e89b4443b4ddbc49af4892bcb929b069069d18d2bd1a5c42f36acc2355951a8d9a47f0dd4bf02e71e",
"378f5a541631229b944c9ad8ec165fde3a7d3a1b258942243cd955b7e00d0984800a440bdbb2ceb17b2b8a9aa6079c540e38dc92cb1f2a607261445183235adb",
"abbedea680056f52382ae548b2e4f3f38941e71cff8a78db1fffe18a1b3361039fe76702af69334b7a1e6c303b7652f43698fad1153bb6c374b4c7fb98459ced",
"7bcd9ed0efc889fb3002c6cd635afe94d8fa6bbbebab076120018021148466798a1d71efea48b9caefbacd1d7d476e98dea2594ac06fd85d6bcaa4cd81f32d1b",
"378ee767f11631bad21380b00449b17acda43c32bcdf1d77f82012d430219f9b5d80ef9d1891cc86e71da4aa88e12852faf417d5d9b21b9948bc924af11bd720"]
# C1 = ["0",
# "b1085bda1ecadae9ebcb2f81c0657c1f2f6a76432e45d016714eb88d7585c4fc4b7ce09192676901a2422a08a460d31505767436cc744d23dd806559f2a64507",
# "6fa3b58aa99d2f1a4fe39d460f70b5d7f3feea720a232b9861d55e0f16b501319ab5176b12d699585cb561c2db0aa7ca55dda21bd7cbcd56e679047021b19bb7",
# "f574dcac2bce2fc70a39fc286a3d843506f15e5f529c1f8bf2ea7514b1297b7bd3e20fe490359eb1c1c93a376062db09c2b6f443867adb31991e96f50aba0ab2",
# "ef1fdfb3e81566d2f948e1a05d71e4dd488e857e335c3c7d9d721cad685e353fa9d72c82ed03d675d8b71333935203be3453eaa193e837f1220cbebc84e3d12e",
# "4bea6bacad4747999a3f410c6ca923637f151c1f1686104a359e35d7800fffbdbfcd1747253af5a3dfff00b723271a167a56a27ea9ea63f5601758fd7c6cfe57",
# "ae4faeae1d3ad3d96fa4c33b7a3039c02d66c4f95142a46c187f9ab49af08ec6cffaa6b71c9ab7b40af21f66c2bec6b6bf71c57236904f35fa68407a46647d6e",
# "f4c70e16eeaac5ec51ac86febf240954399ec6c7e6bf87c9d3473e33197a93c90992abc52d822c3706476983284a05043517454ca23c4af38886564d3a14d493",
# "9b1f5b424d93c9a703e7aa020c6e41414eb7f8719c36de1e89b4443b4ddbc49af4892bcb929b069069d18d2bd1a5c42f36acc2355951a8d9a47f0dd4bf02e71e",
# "378f5a541631229b944c9ad8ec165fde3a7d3a1b258942243cd955b7e00d0984800a440bdbb2ceb17b2b8a9aa6079c540e38dc92cb1f2a607261445183235adb",
# "abbedea680056f52382ae548b2e4f3f38941e71cff8a78db1fffe18a1b3361039fe76702af69334b7a1e6c303b7652f43698fad1153bb6c374b4c7fb98459ced",
# "7bcd9ed0efc889fb3002c6cd635afe94d8fa6bbbebab076120018021148466798a1d71efea48b9caefbacd1d7d476e98dea2594ac06fd85d6bcaa4cd81f32d1b",
# "378ee767f11631bad21380b00449b17acda43c32bcdf1d77f82012d430219f9b5d80ef9d1891cc86e71da4aa88e12852faf417d5d9b21b9948bc924af11bd720"]
# utility functions ------------------------------------------------------------------------------------
# convert from text to binary
def text_bin(s: str) -> str:
return "".join(f"{ord(i):08b}" for i in s)
# convert from text to binary v2 (пока не используется)
def text_to_bin(text):
return ''.join(format(x, '08b') for x in bytearray(text, 'utf-8'))
# convert from binary to hex
def bin_hex(s: str) -> str:
s1 = ""
for i in [s[x:x + 8] for x in range(0, len(s), 8)]:
s1 += hex(int(i, 2))[2:].zfill(2)
return s1
# convert from hex to binary
def hex_bin(hex_s: str) -> str:
mp = [hex_s[i:i + 2] for i in range(0, len(hex_s), 2)]
bin_s = ""
for i in mp:
mp_bin = bin(int(i, 16))[2:]
while len(mp_bin) % 8 != 0: # дополнение нулями
mp_bin = "0" + mp_bin
bin_s += mp_bin
return bin_s
# convert из текста в hex
def text_to_hex(text):
result = ''
for i in range(len(text)):
if i % 4 == 0:
result += hex(int(text[i:i + 4], 2))[2:]
return result
# реверсит текст
def reverse(text):
temp_len = []
result = ''
for i in range(len(text)):
if i % 2 == 0:
temp_len.append(text[i:i + 2])
for i in range(len(temp_len)):
result += temp_len[-1 - i]
return result
# Преобразования короче ---------------------------------------------------------------------------
# Побитовое исключающее ИЛИ над 512-битными блоками (XOR)
def x_change(k, a: str) -> str:
out_list = []
for i in range(len(k)):
out_list.append(str(pow(int(k[i]) + int(a[i]), 1, 2)))
return "".join(out_list)
# Нелинейное биективное преобразование
def S(I: str) -> str:
I_list = []
for i in range(512):
if i % 8 == 0:
c = int(I[i:i + 8], 2)
var = pi_bin[c]
I_list.append(var)
I_str = "".join(I_list)
return I_list
# Перестановка байтов
def P(I: list) -> str:
I_list = [0] * 64
for i in range(64):
I_list[i] = I[tau[i]]
return "".join(I_list)
# Линейное преобразование
def L(I: str) -> str:
b = []
for i in range(512):
if i % 64 == 0:
c = I[i:i + 64]
b.append(c)
return b
# вспомогательная надстройка над линейным п.
def l(b: len):
B_list = []
B_str = ""
for i in range(8):
B = "0" * 64
for j in range(64):
if int(b[i][j]) == 1:
B_str = hex_bin(matrix_A[j])
elif int(b[i][j]) == 0:
B_str = "0" * 64
B = x_change(B, B_str)
B_list.append(B)
return "".join(B_list)
# ну собственно, Е из стандарта
def E(K, m):
state = x_change(K, m)
for i in range(len(C)): # от 0 до 11 по идее
state = l(L(P(S(state))))
K = key_schedule(K, i)
state = x_change(state, K)
return state
# вспомогательная функция, которая тупо вызывает преобразования подряд
def LPSX(smth, smth2):
return l(L(P(S(x_change(smth, smth2))))) # соответствует LPS в стандарте, x_change это xor
# из стандарта (БАНАЛЬНО НО РАБОТАЕТ ЖЕ)
def key_schedule(K, i):
K = LPSX(K, hex_bin(C[i]))
return K
# Преобразование: функция g в стандарте (функция сжатия)
def g(N, m, h: str) -> str:
K = LPSX(h, N) # все стандартные преобразования
# print(bin_hex(K))
t = E(K, m) # функия E из стандарта
t = x_change(h, t) # xor
G = x_change(t, m) # xor
# print(bin_hex(G))
return G
# главная функция в этом пармезанском балете
def stribog_both(M, flag) -> str:
"""
:param M: это массив в бинарном виде (предполагается)
:param flag: 1 - 512, 2 - 256 бит
:return: строка, че
"""
m = M # фактически, просто обьявление (useless)
N = "0" * 512 # N она и в Африке ЭН
Sig = "0" * 512 # наша горячо любимая сигма
if flag == 1: # 512
IV = "0" * 512
elif flag == 2: # 256
IV = "00000001" * 64
else:
print('Ошибка в передаваемом флаге')
exit(-1)
h = IV
while len(M) >= 512:
m = M[len(M) - 512:] # блок (справа-с-конца)
h = g(N, m, h)
# print(bin_hex(h))
N = format(pow(int(N, 2) + 512, 1, pow(2, 512)), "0b")
while len(N) != 512:
N = "0" + N
Sig = format(pow(int(Sig, 2) + int(m, 2), 1, pow(2, 512)), "0b")
while len(Sig) != 512:
Sig = "0" + Sig
M = M[:len(M) - 512]
if len(M) < 512: # длина меньше 512
m = M
m = m = "1" + m
while len(m) != 512: # дополнение
m = "0" + m
h = g(N, m, h)
# print(bin_hex(h))
N = format(pow(int(N, 2) + len(M), 1, pow(2, 512)), "0b")
while len(N) != 512:
N = "0" + N
# print(N)
Sig = format(pow(int(Sig, 2) + int(m, 2), 1, pow(2, 512)), "0b")
while len(Sig) != 512:
Sig = "0" + Sig
# print(Sig)
Nol = "0" * 512
h = g(Nol, N, h)
# print(bin_hex(h))
h = g(Nol, Sig, h)
# print(bin_hex(h))
# return bin_hex(h)
if flag == 1:
return bin_hex(h)
elif flag == 2:
h = h[:256]
return bin_hex(h)
def text_2_approp(text):
return hex_bin(reverse(text_to_hex(text_bin(text))))
pass
if __name__ == '__main__':
# inp = input('Введите текст:\t')
m1 = '323130393837363534333231303938373635343332313039383736353433323130393837363534333231303938373635343332313039383736353433323130'
m2 = 'fbe2e5f0eee3c820fbeafaebef20fffbf0e1e0f0f520e0ed20e8ece0ebe5f0f2f120fff0eeec20f120faf2fee5e2202ce8f6f3ede220e8e6eee1e8f0f2d1202ce8f0f2e5e220e5d1'
print('Начальный вид сообщения из госта:', m1)
print('Начальный вид сообщения2 из госта:', m2)
m1 = hex_bin(m1)
m2 = hex_bin(m2)
print('Сообщение в бинарном виде:', m1)
print('Сообщение2 в бинарном виде:', m2)
# massive = hex_bin(reverse(text_to_hex(text_to_bin(massive))))
# mas = text_2_approp(inp)
mas = m1
mas2 = m2
# choose = input('Выбор свертки\n512 - 1\n256 - 2\n>>>\t')
final = stribog_both(mas, 1)
print(final)
f2 = stribog_both(mas2, 1)
print(f2)
# def test():
# m1 = '323130393837363534333231303938373635343332313039383736353433323130393837363534333231303938373635343332313039383736353433323130'
# m1 = hex_bin(m1)
# m2 = 'fbe2e5f0eee3c820fbeafaebef20fffbf0e1e0f0f520e0ed20e8ece0ebe5f0f2f120fff0eeec20f120faf2fee5e2202ce8f6f3ede220e8e6eee1e8f0f2d1202ce8f0f2e5e220e5d1 '
# m2 = hex_bin(m2)
# test1_1 = '486f64c1917879417fef082b3381a4e211c324f074654c38823a7b76f830ad00fa1fbae42b1285c0352f227524bc9ab16254288dd6863dccd5b9f54a1ad0541b '
# test1_2 = '00557be5e584fd52a449b16b0251d05d27f94ab76cbaa6da890b59d8ef1e159d'
# test2_1 = '28fbc9bada033b1460642bdcddb90c3fb3e56c497ccd0f62b8a2ad4935e85f037613966de4ee00531ae60f3b5a47f8dae06915d5f2f194996fcabf2622e6881e '
# test2_2 = '508f7e553c06501d749a66fc28c6cac0b005746d97537fa85d9e40904efed29d'
# print(stribog_256_512(m1, 1) == test1_1, stribog_256_512(m1, 2) == test1_2, stribog_256_512(m2, 1) == test2_1,
# stribog_256_512(m2, 2) == test2_2, sep='\n')