public byte[] diff(byte[] block, GenericBlockCipher cipher) { for (int j = 0; j < block.Length; j++) { block[j] = (byte)(block[j] ^ cipher.Key[j % cipher.Key.Length]); } return(block); }
public void Generic_GenericBlock() { GenericBlockCipher gbc = new GenericBlockCipher(); gbc.DiffuseFunction = diff; gbc.ConfuseFunction = conf; gbc.InverseDiffuseFunction = diff; gbc.InverseConfuseFunction = conf; gbc.Key = BitConverter.GetBytes(0x133457799BBCDFF1); byte[] clear = BitConverter.GetBytes(0x0123456789ABCDEF); gbc.BlockSize = gbc.Key.Length * 8;//this is to get this working without padding byte[] cipher = gbc.Encrypt(clear); CollectionAssert.AreNotEqual(clear, cipher); byte[] plain = gbc.Decrypt(cipher); CollectionAssert.AreEqual(clear, plain); }
public byte[] conf(byte[] block, GenericBlockCipher cipher) { Array.Reverse(block); return(block); }