实现 Byte[] 操作时遇到问题

Trouble with realization Byte[] operations

我对byte[]使用异或运算

public static byte[] XOR(byte[] buffer1, byte[] buffer2)
{
    for (int i = 0; i < buffer1.Length; i++)
        buffer1[i] ^= buffer2[i];
    return buffer1;
}

并实现哈希算法的移位方法。

public static byte[] RotHi(byte[] B, int count)
{
    for (int i = 0; i < count; i++)
    {
        byte[] a = ShHi(B);
        byte[] b = B;
        for (int j = (B.Length * 8) - 2; j >=0 ; j--)
        {
            b = ShLo(b);
        }
        B = XOR(a,b);
    }
    return B;
}
public static byte[] ShHi(byte[] B)
{
    return BitConverter.GetBytes(BitConverter.ToUInt64(B, 0) >> 1);
}
public static byte[] ShLo(byte[] B)
{
    return BitConverter.GetBytes(BitConverter.ToUInt64(B, 0) << 1);
}

当它单独运行时结果是正确的

W0 = b194bac80a08f53b.
W1 = e12bdc1ae28257ec.
W2 = e9dee72c8f0c0fa6.
m1 = 8; n1 = 53.

T0 = RotHi(W0, m1); // 3bb194bac80a08f5
W0 = XOR(W0,W1);
W0 = XOR(W0,W2); // b96181fe6786ad71

但下一个代码 return 拧出结果^

T1 = XOR(W1,(RotHi(W0, n1))); // ed242f26d7e9da27, but should be CDFB23D652B779DB

怎么了?

字节顺序有问题。注意 Big Endian 或 Little Endian。