@@ -281,14 +281,15 @@ def generate_cipher(self, decrypt=False, mode="ECB"):
281281
282282
283283if __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)
285286 # 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 )
287288 #fancyDES = FancyDES(path='LICENSE', key = 'HELLO WORLD! HAHAHHA', fromFile=True)
288289
289290 b = bytearray (fancyDES .message )
290291
291- cipher = fancyDES .generate_cipher (mode = "CBC" )
292+ cipher = fancyDES .generate_cipher (mode = MODE )
292293 print ('Encrypted:' )
293294 print (binascii .hexlify (cipher ), len (cipher ))
294295
@@ -303,11 +304,11 @@ def generate_cipher(self, decrypt=False, mode="ECB"):
303304 # check changed ciphertext
304305 # cipher[4] += 1
305306
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 ()
309310 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 )
311312 print ('Decrypted:' )
312313 # print(binascii.hexlify(plainteks), len(plainteks))
313314 print (plainteks , len (plainteks ))
0 commit comments