예제 #1
0
파일: fishc.py 프로젝트: MZCryp/blowfish
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()
예제 #2
0
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()
예제 #3
0
 def test_once(self):
     zero_block = bytearray(b'\x00' * Blowfish.blockSize())
     self.cipher.encrypt(zero_block)