def main(mode, key, infile, outfile): cipher = Blowfish(bytearray.fromhex(key)) text = infile.read() size = Blowfish.blockSize() for i in range(0,len(text),size): block = bytearray(text[i:(i+size)]) if len(block)<size: for _ in range(size-len(block)): block.append(0) if mode==MODE_ENCRYPT: cipher.encrypt(block) elif mode==MODE_DECRYPT: cipher.decrypt(block) outfile.write(block) outfile.flush()
def main(mode, key, infile, outfile): cipher = Blowfish(bytearray.fromhex(key)) text = infile.read() size = Blowfish.blockSize() for i in range(0, len(text), size): block = bytearray(text[i:(i + size)]) if len(block) < size: for _ in range(size - len(block)): block.append(0) if mode == MODE_ENCRYPT: cipher.encrypt(block) elif mode == MODE_DECRYPT: cipher.decrypt(block) outfile.write(block) outfile.flush()
def test_once(self): zero_block = bytearray(b'\x00' * Blowfish.blockSize()) self.cipher.encrypt(zero_block)