@@ -281,14 +281,15 @@ def generate_cipher(self, decrypt=False, mode="ECB"):
281
281
282
282
283
283
if __name__ == '__main__' :
284
- fancyDES = FancyDES (path = 'samples/short.txt' ,key = 'HELLO WORLD! HAHAHHA' , fromFile = True )
284
+ MODE = "OFB"
285
+ # fancyDES = FancyDES(path='samples/short.txt',key = 'HELLO WORLD! HAHAHHA', fromFile=True)
285
286
# fancyDES = FancyDES(path='samples/text.txt',key = 'HELLO WORLD! HAHAHHA', fromFile=True)
286
- # fancyDES = FancyDES(path='samples/lorem-ipsum.txt',key = 'HELLO WORLD! HAHAHHA', fromFile=True)
287
+ fancyDES = FancyDES (path = 'samples/lorem-ipsum.txt' ,key = 'HELLO WORLD! HAHAHHA' , fromFile = True )
287
288
#fancyDES = FancyDES(path='LICENSE', key = 'HELLO WORLD! HAHAHHA', fromFile=True)
288
289
289
290
b = bytearray (fancyDES .message )
290
291
291
- cipher = fancyDES .generate_cipher (mode = "CBC" )
292
+ cipher = fancyDES .generate_cipher (mode = MODE )
292
293
print ('Encrypted:' )
293
294
print (binascii .hexlify (cipher ), len (cipher ))
294
295
@@ -303,11 +304,11 @@ def generate_cipher(self, decrypt=False, mode="ECB"):
303
304
# check changed ciphertext
304
305
# cipher[4] += 1
305
306
306
- # f = open('samples/output/output-OFB .txt', 'wb')
307
- # f.write(cipher)
308
- # f.close()
307
+ f = open ('samples/output/output-' + MODE + ' .txt' , 'wb' )
308
+ f .write (cipher )
309
+ f .close ()
309
310
fancyDES1 = FancyDES (message = cipher , key = 'HELLO WORLD! HAHAHHA' , fromFile = False )
310
- plainteks = fancyDES1 .generate_cipher (decrypt = True , mode = "CBC" )
311
+ plainteks = fancyDES1 .generate_cipher (decrypt = True , mode = MODE )
311
312
print ('Decrypted:' )
312
313
# print(binascii.hexlify(plainteks), len(plainteks))
313
314
print (plainteks , len (plainteks ))
0 commit comments