public static uint h(ITwofishMDS mds, uint x, uint[] L) { int k = L.Length; uint[] y = Word32Bits.ToUintBytes(x); if (k == 4) { y[0] = (uint)q1(y[0]) ^ Word32Bits.GetByte(L[3], 0); y[1] = (uint)q0(y[1]) ^ Word32Bits.GetByte(L[3], 1); y[2] = (uint)q0(y[2]) ^ Word32Bits.GetByte(L[3], 2); y[3] = (uint)q1(y[3]) ^ Word32Bits.GetByte(L[3], 3); } if (k >= 3) { y[0] = (uint)q1(y[0]) ^ Word32Bits.GetByte(L[2], 0); y[1] = (uint)q1(y[1]) ^ Word32Bits.GetByte(L[2], 1); y[2] = (uint)q0(y[2]) ^ Word32Bits.GetByte(L[2], 2); y[3] = (uint)q0(y[3]) ^ Word32Bits.GetByte(L[2], 3); } y[0] = (uint)(q0(q0(y[0]) ^ Word32Bits.GetByte(L[1], 0)) ^ Word32Bits.GetByte(L[0], 0)); y[1] = (uint)(q0(q1(y[1]) ^ Word32Bits.GetByte(L[1], 1)) ^ Word32Bits.GetByte(L[0], 1)); y[2] = (uint)(q1(q0(y[2]) ^ Word32Bits.GetByte(L[1], 2)) ^ Word32Bits.GetByte(L[0], 2)); y[3] = (uint)(q1(q1(y[3]) ^ Word32Bits.GetByte(L[1], 3)) ^ Word32Bits.GetByte(L[0], 3)); return(mds.Multiply(y)); }
public void GetByte_GetsByteFromWord_GotByte() { uint value = 1305570306; Assert.AreEqual(2, Word32Bits.GetByte(value, 0)); Assert.AreEqual(108, Word32Bits.GetByte(value, 1)); Assert.AreEqual(209, Word32Bits.GetByte(value, 2)); Assert.AreEqual(77, Word32Bits.GetByte(value, 3)); }