-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrcncipher.py
More file actions
738 lines (554 loc) · 19.9 KB
/
rcncipher.py
File metadata and controls
738 lines (554 loc) · 19.9 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
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
from collections import deque #library used for rotation
import numpy as np
# all required matrix
RS_matrix=[[0x01,0xA4,0x55,0x87,0x5A,0x58,0xDB,0x9E],[0xA4,0x56,0x82,0xF3,0x1E,0xC6,0x68,0xE5],[0x02,0xA1,0xFC,0xC1,0x47,0xAE,0x3D,0x19],[0xA4,0x55,0x87,0x5A,0x58,0xDB,0x9E,0x03]]
tq0=[[0x8,0x1,0x7,0xD,0x6,0xF,0x3,0x2,0x0,0xB,0x5,0x9,0xE,0xC,0xA,0x4],[0xE,0xC,0xB,0x8,0x1,0x2,0x3,0x5,0xF,0x4,0xA,0x6,0x7,0x0,0x9,0xD],[0xB,0xA,0x5,0xE,0x6,0xD,0x9,0x0,0xC,0x8,0xF,0x3,0x2,0x4,0x7,0x1],[0xD,0x7,0xF,0x4,0x1,0x2,0x6,0xE,0x9,0xB,0x3,0x0,0x8,0x5,0xC,0xA]]
tq1=[[0x2,0x8,0xB,0xD,0xF,0x7,0x6,0xE,0x3,0x1,0x9,0x4,0x0,0xA,0xC,0x5],[0x1,0xE,0x2,0xB,0x4,0xC,0x3,0x7,0x6,0xD,0xA,0x5,0xF,0x9,0x0,0x8],[0x4,0xC,0x7,0x5,0x1,0x6,0x9,0xA,0x0,0xE,0xD,0x8,0x2,0xB,0x3,0xF],[0xB,0x9,0x5,0x1,0xC,0x3,0xD,0xE,0x6,0x4,0x7,0xF,0x2,0x0,0x8,0xA]]
MDS=[[0x01,0xEF,0x5B,0x5B],[0x5B,0xEF,0xEF,0x01],[0xEF,0x5B,0x01,0xEF],[0xEF,0x01,0xEF,0x5B]]
# Polynomials used for multiplication in RF and MDS matrix
gf_mod = 2**8 + 2**6 + 2**5 + 2**3 + 1
rs_mod = 2**8 + 2**6 + 2**3 + 2**2 + 1
t=[tq0,tq1]
S0=[]
S1=[]
# Function to multiply in Galois Field with correct polynomial
# Here modulus is used as the value of 2^n in the polynomial
def gf2n_multiply(a, b,modulus):
overflow = 0x100
sum1 = 0
while (b > 0):
if (b & 1):
sum1 = sum1 ^ a
b = b >> 1
a = a << 1
if (a & overflow):
a = a ^ modulus
return sum1
# Right rotation of number with rotation and bits as the parameter
def ROR(num,rot,bits):
num=bin(num)[2:]
num=num.zfill(bits)
num=[int(i) for i in num]
items=deque(num)
items.rotate(rot)
num=list(items)
num=''.join([str(i) for i in num])
num=int(num,2)
return num
# Left rotation of number with rotation and bits as the parameter
def ROL(num,rot,bits):
num=bin(num)[2:]
num=num.zfill(bits)
num=[int(i) for i in num]
items=deque(num)
items.rotate(-rot)
num=list(items)
num=''.join([str(i) for i in num])
num=int(num,2)
return num
# Permuatation function q1 used in the SBOX
def q1(inp):
t0=t[1][0]
t1=t[1][1]
t2=t[1][2]
t3=t[1][3]
inp=bin(inp)[2:]
inp=inp.zfill(8)
a0=int(inp[:4],2)
b0=int(inp[4:],2)
a1=a0^b0
b1=a0^(ROR(b0,1,4))^((8*a0)%16)
a2=t0[a1]
b2=t1[b1]
a3=a2^b2
b3=a2^(ROR(b2,1,4))^((8*a2)%16)
a4=t2[a3]
b4=t3[b3]
y=16*b4+a4
return y
# Permuatation function q0 used in the SBOX
def q0(inp):
t0=t[0][0]
t1=t[0][1]
t2=t[0][2]
t3=t[0][3]
inp=bin(inp)[2:]
inp=inp.zfill(8)
a0=int(inp[:4],2)
b0=int(inp[4:],2)
a1=a0^b0
b1=a0^(ROR(b0,1,4))^((8*a0)%16)
a2=t0[a1]
b2=t1[b1]
a3=a2^b2
b3=a2^(ROR(b2,1,4))^((8*a2)%16)
a4=t2[a3]
b4=t3[b3]
y=16*b4+a4
return y
# pseudo-Hadamard transform (PHT) function
# a=(a+b)% 2^32
# b=(a+2b)% 2^32
def PHT(a,b):
num1=(a+b)%(pow(2,32))
num2=(a+2*b)%pow(2,32)
return num1,num2
# g function used inside the F function
def g_function(inp_r):
global S0,S1
S_0=S0
S_1=S1
arr=[]
h=hex(inp_r)[2:].zfill(8)
for i in range(0,len(h),2):
tmp=int(h[i:i+2],16)
arr.append(tmp)
arr=arr[::-1]
inp0=arr[0]
inp1=arr[1]
inp2=arr[2]
inp3=arr[3]
output=[0,0,0,0]
# Taking the output of the SBOXES used in the G_function
output[0] = q1(q0(q0(inp0) ^ S_0[0]) ^ S_1[0])
output[1] = q0(q0(q1(inp1) ^ S_0[1]) ^ S_1[1])
output[2] = q1(q1(q0(inp2) ^ S_0[2]) ^ S_1[2])
output[3] = q0(q1(q1(inp3) ^ S_0[3]) ^ S_1[3])
# Matrix multiplication under the Galois filed with modulus of GF
output=mat_mul(MDS,output,gf_mod)
# Little endian
output=output[::-1]
# Combining 4 8-bit numbers to 1 32-bit number
output=int(''.join([bin(i)[2:].zfill(8) for i in output]),2)
return output
# A helper function for the main function H used in round key generation
def helper_h(inp1,M1,M2):
output=[0,0,0,0]
output[0] = q1(q0(q0(inp1) ^ M1[0]) ^ M2[0])
output[1] = q0(q0(q1(inp1) ^ M1[1]) ^ M2[1])
output[2] = q1(q1(q0(inp1) ^ M1[2]) ^ M2[2])
output[3] = q0(q1(q1(inp1) ^ M1[3]) ^ M2[3])
output=mat_mul(MDS,output,gf_mod)
return output
# H function used in key scheduling
def h_function(M_even,M_odd):
M0=M_even[0]
M2=M_even[1]
M1=M_odd[0]
M3=M_odd[1]
K_keys=[]
# Loop for making 40 keys
for i in range(0,57,2):
inp1=i
inp2=i+1
# Calling helper function which is performing the S-Box operations
key1=helper_h(inp1,M2,M0)
key2=helper_h(inp2,M3,M1)
fin_key1=[]
fin_key2=[]
# Making the 4 8-bit keys to a combined 32 bit key with adjusting little endian
for i in range(4):
fin_key1.append(bin(key1[i])[2:].zfill(8))
fin_key2.append(bin(key2[i])[2:].zfill(8))
fin_key1=fin_key1[::-1]
fin_key2=fin_key2[::-1]
# binary to decimal conversion
key1=int(''.join(fin_key1),2)
key2=int(''.join(fin_key2),2)
# Rotating the key by 8 bits
key2=ROL(key2,8,32)
# pseudo-Hadamard transform of the key1 and key2
key1,key2=PHT(key1,key2)
# Left rotation by 9 bits of key2
key2=ROL(key2,9,32)
# Finally appending the keys to main key list
K_keys.append(key1)
K_keys.append(key2)
return K_keys
# A function for matrix multiplication which uses the Field multiplication and addition rules
def mat_mul(mat1,mat2,modulus):
row1=len(mat1)
col1=len(mat1[0])
fin=[]
for i in range(row1):
val=0
for j in range(col1):
tmp1=gf2n_multiply((mat1[i][j]),mat2[j],modulus)
val=val^tmp1
fin.append(val)
return fin
# Main function for Key scheduling
def key_schedule(key):
global S0,S1
m_array=[]
# array of 16 8 bit-keys provided by user
for i in range(0,len(key),2):
tmp=int(key[i:i+2],16)
m_array.append(tmp)
# Making the Sbox S0 and S1 with RS modulo multiplication
S0=mat_mul(RS_matrix,m_array[:8],rs_mod)
S1=mat_mul(RS_matrix,m_array[8:16],rs_mod)
# Odd even matrix for round keys generation
M_even=[]
M_odd=[]
val=0
# Making the even and odd lists
for i in range(0,len(m_array),4):
tmp=m_array[i:i+4]
if(val%2==0):
M_even.append(tmp)
else:
M_odd.append(tmp)
val+=1
# Calling H function with parameter Meven and Modd
K_keys=h_function(M_even,M_odd)
# for i in range(0,40,2):
# print(hex(K_keys[i])[2:].zfill(8),hex(K_keys[i+1])[2:].zfill(8))
return K_keys
# Function for Input Whitening
def whitening(plaintext,white_keys):
plain=[]
new_key=[]
val=0
# Converting plaintext to a array of 16 length
for i in range(0,len(plaintext),2):
tmp=int(plaintext[i:i+2],16)
plain.append(tmp)
arr2=[]
# taking 4 8-bit number together and then adjusting little endian
for i in range(0,len(plain),4):
tmp=plain[i:i+4]
tmp=tmp[::-1] #reversing the list for little endian adjustments
arr2+=tmp
plain=arr2
# Expanding 4 32 bit numbers to 16 8-bit number array
for j in range(len(white_keys)):
x=hex(white_keys[j])[2:].zfill(8)
for k in range(0,len(x),2):
tmp=int(x[k:k+2],16)
new_key.append(tmp)
r_array=[]
# Now both key and plaintext is 16 8-bit array so we can XOR
for i in range(len(plain)):
r_array.append((new_key[i]^plain[i]))
# Returning the round State
r0=r_array[:4]
r1=r_array[4:8]
r2=r_array[8:12]
r3=r_array[12:16]
r_array=[r0,r1,r2,r3]
return r_array
# The F function used in Encryption
def f_function(r_array,k1,k2):
r0=r_array[0]
r1=r_array[1]
# Rotationg left
r1=ROL(r1,8,32)
# Calling G function for r0 and r1 and then obtaining t0 and t1
t0=g_function(r0)
t1=g_function(r1)
# print(hex(t0),end= " ")
# print(hex(t1))
# exit()
# pseudo-Hadamard transform of t0 and t1
t0,t1=PHT(t0,t1)
# addition of round keys with modulo 2^32
f0=(t0+k1)%pow(2,32)
f1=(t1+k2)%pow(2,32)
# returning f0 and f1
return f0,f1
# Method for performing K-Rail Fence Encryption on given plaintext
def encryptRailFence(plaintext, key):
# Filter out spaces from the plaintext (spaces are ignored for encipherment)
plaintext = "".join(plaintext.split())
# Creation of the matrix 'rail' filled with placeholders (ph)
rail = [['ph' for i in range(len(plaintext))] # length of plaintext = number of columns
for j in range(key)] # key = number of rows
# Initialized information for sense of direction and values of row/col
direction_down = False
col = 0
row = 0
for i in range(len(plaintext)):
# Check the direction of flow (is it the first row or last row?)
if (row == 0) or (row == key - 1):
direction_down = not direction_down # Invert direction if yes
# Begin filling the cipher matrix
rail[row][col] = plaintext[i]
col += 1
# Change rows based on the flag variable 'direction_down' logic
if direction_down:
row += 1
else:
row -= 1
# After the matrix has been filled, we can now extract that information to create the ciphertext
ciphertext = []
for i in range(key): # Rows
for j in range(len(plaintext)): # Columns
if rail[i][j] != 'ph': # If the value is not a placeholder, append it to the ciphertext list
ciphertext.append(rail[i][j])
return "".join(ciphertext) # Convert the ciphertext list into a singular string
#-------------------------------------------------------------------------------
# Decryption
# Method for performing n-Rail Fence Decryption on given ciphertext
def decryptRailFence(ciphertext, key):
# Creation of the matrix 'rail' filled with placeholders (similar to encryption algorithm)
rail = [['*' for i in range(len(ciphertext))]
for j in range(key)]
## Initialized information for sense of direction and values of row/col
direction_down = None
col = 0
row = 0
# Create markers on the matrix with 'mkr'
for i in range(len(ciphertext)):
if row == 0: # Highest level row
direction_down = True
if row == key - 1: # Lowest level row
direction_down = False
# Begin filling the matrix with markers based on the key and length of text
rail[row][col] = 'mkr'
col += 1
# Change row index based on the flag variable 'direction_down' logic
if direction_down:
row += 1
else:
row -= 1
# For loop to begin filling marked spots with characters from the ciphertext
# idx = indexing for ciphertext, i = row index, j = col index
idx = 0
for i in range(key):
for j in range(len(ciphertext)):
if ((rail[i][j] == 'mkr') and
(idx < len(ciphertext))):
rail[i][j] = ciphertext[idx]
idx += 1
# Begin reading the filled rail matrix in a zigzag manner
plaintext = []
col = 0
row = 0
for i in range(len(ciphertext)):
if row == 0: # Highest level row
direction_down = True
if row == key - 1: # Lowest level row
direction_down = False
# Begin constructing the plaintext
plaintext.append(rail[row][col])
col += 1
# Change rows based on the flag variable 'direction_down' logic
if direction_down:
row += 1
else:
row -= 1
return "".join(plaintext) # Convert the plaintext list into a singular string
def getUL(matrixKeys):
matrixKeys = [str(hex(item))[2:] for item in matrixKeys]
#join nested
matrixKeys = "".join(matrixKeys)
matrixKeys2 = []
for i in range(4):
matrixKeys2.append([])
for j in range(4):
matrixKeys2[-1].append(int(matrixKeys[i*4 + 2*j] + matrixKeys[i*4 + 2*j + 1], 16))
matrixKeys2 = np.array(matrixKeys2)
U = []
L = []
for i in range(4):
U.append([])
L.append([])
for j in range(4):
if(i < j):
U[-1].append(matrixKeys2[i][j])
L[-1].append(0)
elif(i > j):
U[-1].append(0)
L[-1].append(matrixKeys2[i][j])
else:
U[-1].append(1)
L[-1].append(matrixKeys2[i][j] + 1)
U = np.array(U)
L = np.array(L)
return U,L
def encryptMatrixCipher(plaintext, matrixKeys):
# print(plaintext)
matrixOutput = []
for i in range(4):
matrixOutput.append([])
for j in range(4):
matrixOutput[-1].append(int(plaintext[i*8 + 2*j] + plaintext[i*8 + 2*j + 1], 16))
U,L = getUL(matrixKeys)
# print(L)
# print(matrixOutput)
matrixOutput = np.array(matrixOutput)
cipher1 = np.bitwise_xor(U, matrixOutput)
cipher2 = np.bitwise_xor(L, cipher1)
# print(cipher2)
# print(matrixOutput)
# print(plain2)
# print(plain1)
# print(np.bitwise_xor(U, np.bitwise_xor(L, cipher2)))
# print(matrixOutput)
# print(cipher1)
# print(cipher2)
# Uinv = np.linalg.inv(U)
# Linv = np.linalg.inv(L) % 256
# plain1 = np.dot(Linv, cipher2) % 256
# plain2 = np.dot(plain1, Uinv) % 256
# print(matrixOutput)
# print(plain1)
# print(plain2)
return cipher2
def decryptMatrixCipher(ciphertext, matrixKeys):
matrixOutput = []
# print(ciphertext)
for i in range(4):
matrixOutput.append([])
for j in range(4):
matrixOutput[-1].append(int(ciphertext[i*8 + 2*j] + ciphertext[i*8 + 2*j + 1], 16))
U,L = getUL(matrixKeys)
# Uinv = np.linalg.inv(U)
# Linv = np.linalg.inv(L)
matrixOutput = np.array(matrixOutput)
# print(matrixOutput)
plain2 = np.bitwise_xor(L, matrixOutput)
plain1 = np.bitwise_xor(U, plain2)
# print(plain1)
# matrixOutput = np.array(matrixOutput)
# cipher1 = np.bitwise_xor(U, matrixOutput)
# cipher2 = np.bitwise_xor(L, cipher1)
output = ""
for i in range(4):
for j in range(4):
# print(hex(plain1[i][j]))
output += hex(plain1[i][j])[2:].zfill(2)
# output = [hex(item)[2:].zfill(2) for sublist in plain1 for item in sublist]
output = "".join(output)
# print(output)
return output
# Encrypt function of Twofish
def encrypt(plaintext,key):
key = key.zfill(32)
plaintext = plaintext.zfill(32)
# Making the required keys
round_keys=key_schedule(key)
white_keys=round_keys[:4]
output_keys=round_keys[4:8]
# Whitening the Input
r1_array=whitening(plaintext,white_keys)
r_array=[]
# Converting the array to a 16 8-bit numbers from 4 32-bit number
for i in r1_array:
num=int("".join([bin(j)[2:].zfill(8) for j in i]),2)
r_array.append(num)
# looping 16 time for each round
for r in range(16):
# Calling F function
f0,f1=f_function(r_array,round_keys[2*r+8],round_keys[2*r+9])
c2=f0^r_array[2]
c2=ROR(c2,1,32)
r3=r_array[3]
c3=ROL(r3,1,32)
c3=f1^c3
r_array=[c2,c3,r_array[0],r_array[1]]
# undo the steps
r_array=[r_array[2],r_array[3],r_array[0],r_array[1]]
# printing the output
ciphertext=[]
for i in range(len(output_keys)):
ciphertext.append(hex((output_keys[i]^r_array[i]))[2:].zfill(8))
# converting little endian
output=""
for i in ciphertext:
ans=[i[j:j+2] for j in range(0,len(i),2)]
ans=ans[::-1]
output+=''.join(ans)
for i in range(4):
#pick last two numbers from round key
rails = int(str(round_keys[40])[2*i:2*i+2])
output = encryptRailFence(output, rails+2)
# matrixKeys = [str(hex(item))[2:] for item in round_keys[41:45]]
# print("before matrix cipher:", output)
output = encryptMatrixCipher(output, round_keys[41+i*4:45+i*4])
output = [hex(item)[2:].zfill(2) for sublist in output for item in sublist]
output = "".join(output)
# print(output, i)
# print("Matrix Cipher:", output)
# print(U)
# print(L)
# print("M:", matrixOutput)
# cipher = np.dot(matrixOutput, U) % 256
# print(cipher)
# # print(np.dot(matrixOutput, L))
# invU = np.linalg.inv(U)
# invL = np.linalg.inv(L)
# print("M:", np.dot(cipher, invU) % 256)
return(output)
# Decryption fucntion
def decrypt(ciphertext,key):
key = key.zfill(32)
ciphertext = ciphertext.zfill(32)
# Making the required keys with scheduling
round_keys=key_schedule(key)
white_keys=round_keys[:4]
output_keys=round_keys[4:8]
# print("before decrypt matrix cipher:", ciphertext)
for i in range(3,-1,-1):
ciphertext = decryptMatrixCipher(ciphertext, round_keys[41+i*4:45+i*4])
rails = int(str(round_keys[40])[2*i:2*i+2])
ciphertext = decryptRailFence(ciphertext, rails+2)
# Converting ciphertext to array of 16
ciphertext=[ciphertext[i:i+8] for i in range(0,len(ciphertext),8) ]
r_array=[]
# Adjusting the little endian format
for i in ciphertext:
q=i
s=[]
for j in range(0,len(q),2):
s.append(q[j:j+2])
s=s[::-1]
s=''.join(s)
r_array.append(int(s,16))
# Ciphertext whitening with output whiten keys
for j in range(len(output_keys)):
r_array[j]=(r_array[j]^output_keys[j])
# Doing the criss cross swapping in Fiestal cipher
r_array=[r_array[2],r_array[3],r_array[0],r_array[1]]
# Calling the loop for 16 rounds
for r in range(15,-1,-1):
# Reversing the states ,the 3rd and 4th element will be 1st and 2nd element of previous round state array
a=r_array[2]
b=r_array[3]
c2=r_array[0]
c3=r_array[1]
# Calling the F function with the 3rd and 4th element
f0,f1=f_function([a,b],round_keys[2*r+8],round_keys[2*r+9])
# Reversing to get the r2 and r3 of previous round in ecryption
r2=ROL(c2,1,32)
r2=r2^f0
r3=f1^c3
r3=ROR(r3,1,32)
r_array=[a,b,r2,r3]
# After 16 rounds ,whitening the array with input whiten keys this time
for i in range(4):
r_array[i]=hex((r_array[i]^white_keys[i]))[2:].zfill(8)
ans=""
# Printing the output in Big Endian format
for i in r_array:
tmp=[]
for j in range(0,len(i),2):
tmp.append(i[j:j+2])
tmp=tmp[::-1]
ans+=''.join(tmp)
return(ans)
# typ="encrypt" or input("Enter the type (Encrypt/Decrypt) : ")
# key="898989" or input("Enter the key 128 bit (Hexadecimal) : ")
# key=key.zfill(32)
# if(typ.lower()=="encrypt"):
# plaintext="c0ffee" or input("Enter the plaintext 128 bit (Hexadecimal) : ")
# plaintext=plaintext.zfill(32)
# print("The Ciphertext is : ")
# hello = encrypt(plaintext,key)
# print(hello)
# print("Decrypted: ", decrypt(hello,key))
# else:
# Ciphertext=input("Enter the Ciphertext 128 bit (Hexadecimal) : ")
# print("The Decoded plaintext is : ",end=" ")
# print(decrypt(Ciphertext,key))