package aalg.crypto;

public class BlowfishDecryptor extends BlowfishBase implements IBlockCipherTransformation{

	private final Blowfish cipher;
	public BlowfishDecryptor(Blowfish cipher) {
		this.cipher = cipher;
	}

	@Override
	public IBlockCipher getCipher() {
		return cipher;
	}

	@Override
	public void transformBlock(byte[] sourceBlock, int sourceOffset,
			byte[] targetBlock, int targetOffset) {
		
		if (sourceBlock.length - sourceOffset < (Blowfish.DATA_LENGTH))
			throw new RuntimeException("too big offset");
			
		long newBlock = 0;					
		newBlock = byteArray_to_long(sourceBlock, sourceOffset, Blowfish.DATA_LENGTH);	
		
		newBlock = feistel(newBlock, 17);
		
		for(int i = targetOffset; i< Blowfish.DATA_LENGTH+targetOffset ; i++)
		{
			 targetBlock[i] = (byte)((newBlock >> (56 - 8*i)) & 0xFF) ;
		
			// System.out.println(Integer.toBinaryString(targetBlock[i]& 0xFF));
		}
		
	}

	

}
