public void RotateLeft_RotatesTwoBits_Rotated() { uint value = 2147483649; uint expected = 6; Assert.AreEqual(expected, Word32Bits.RotateLeft(value, 2)); }
public void RotateLeft_RotatesOneBit_Rotated() { uint value = 2147483649; uint expected = 3; Assert.AreEqual(expected, Word32Bits.RotateLeft(value)); }
private uint[] Round(ITwofishMDS mds, uint[] K, int round) { uint F0 = TwofishFunction.h(mds, K[0], _key.SBox); uint F1 = TwofishFunction.h(mds, Word32Bits.RotateLeft(K[1], 8), _key.SBox); K[2] ^= F0 + F1 + _key.K[2 * round + 8]; K[2] = Word32Bits.RotateRight(K[2], 1); K[3] = Word32Bits.RotateLeft(K[3], 1) ^ (F0 + 2 * F1 + _key.K[2 * round + 9]); return(K); }
private void CalculateWords(uint[] words) { for (int i = 8; i < 16; i++) { words[i] = Word32Bits.RotateLeft((uint)(words[i - 8] ^ words[i - 5] ^ words[i - 3] ^ words[i - 1] ^ PHI ^ (i - 8)), 11); } Array.Copy(words, 8, words, 0, 8); for (int i = 8; i < 132; i++) { words[i] = Word32Bits.RotateLeft((uint)(words[i - 8] ^ words[i - 5] ^ words[i - 3] ^ words[i - 1] ^ PHI ^ i), 11); } }
public static uint[] Transform(uint[] x) { x[0] = Word32Bits.RotateLeft(x[0], 13); x[2] = Word32Bits.RotateLeft(x[2], 3); x[1] = x[1] ^ x[0] ^ x[2]; x[3] = x[3] ^ x[2] ^ x[0] << 3; x[1] = Word32Bits.RotateLeft(x[1], 1); x[3] = Word32Bits.RotateLeft(x[3], 7); x[0] = x[0] ^ x[1] ^ x[3]; x[2] = x[2] ^ x[3] ^ x[1] << 7; x[0] = Word32Bits.RotateLeft(x[0], 5); x[2] = Word32Bits.RotateLeft(x[2], 22); return(x); }
private uint[] GetK(uint[] Me, uint[] Mo) { var k = new uint[40]; uint p = 16843009; var mds = new TwofishMDS(); for (int i = 0; i < 20; i++) { uint A = TwofishFunction.h(mds, (uint)(2 * i * p), Me); uint B = Word32Bits.RotateLeft(TwofishFunction.h(mds, (uint)((2 * i + 1) * p), Mo), 8); k[2 * i] = A + B; k[2 * i + 1] = Word32Bits.RotateLeft(A + 2 * B, 9); } return(k); }