private static void QuarterRound(uint[] set, uint a, uint b, uint c, uint d) { set[b] ^= BitShift.RotateLeft32(set[a] + set[d], 7); set[c] ^= BitShift.RotateLeft32(set[b] + set[a], 9); set[d] ^= BitShift.RotateLeft32(set[c] + set[b], 13); set[a] ^= BitShift.RotateLeft32(set[d] + set[c], 18); }
public void TestShiftByteRight_AutocastsToInt() { var guineaPig = new BitShift(); const byte pellet1 = 34; const int shiftSize = 2; var result = guineaPig.ShiftByte(pellet1, shiftSize, ShiftDirection.Right); Assert.AreEqual(typeof(int), result.GetType()); }
public void BeginRead(IAsyncResult asyncResult) { try { int received = Stream.EndRead(asyncResult); if (received != 0) { while (received >= 6) { int length = BitConverter.ToUInt16(buffer, 0) & 0x7FFF; byte[] temp = new byte[length + 2]; Array.Copy(buffer, 2, temp, 0, temp.Length); int bits = Id % 7 + 1; BitShift.Unshift(temp, bits); byte[] opcode = new byte[] { temp[0], temp[1] }; RecvOpcode packet = (RecvOpcode)BitConverter.ToUInt16(opcode, 0); Type t = Type.GetType("PiercingBlow.Login.Network.Recv." + packet.ToString()); if (t != null) { ClientPacket clientpacket = (ClientPacket)Activator.CreateInstance(t); clientpacket.Client = this; clientpacket.Init(temp); //clientpacket.Process(temp); } else { Log.Info("PacketId = {0}", BitConverter.ToUInt16(opcode, 0), buffer.Length); Log.Trace(temp.ToHex()); } received -= length + 4; Array.Copy(buffer, length + 4, buffer, 0, received); // << Копируем оставшиеся данные в начало буфера } Stream.BeginRead(buffer, 0, buffer.Length, BeginRead, Stream); } else { OnDisconnected(this); } } catch (IOException) { OnDisconnected(this); } catch (Exception ex) { OnDisconnected(this); //Log.Error(ex); Log.Error($"{ex.Message}\n{ex.StackTrace}"); } }
public void TestShiftRight_ShiftBy8() { var guineaPig = new BitShift(); const int pellet1 = 34234225; const int shiftSize = 8; int divisor = (int)Math.Pow(2, shiftSize); Assert.AreNotEqual(shiftSize, divisor, "Test setup error"); int truth = pellet1 / divisor; Assert.AreEqual(truth, BitShift.ShiftRight(pellet1, shiftSize)); }
private static void QuarterRound(uint[] set, uint a, uint b, uint c, uint d) { set[a] = unchecked (set[a] + set[b]); set[d] = BitShift.RotateLeft32(unchecked (set[d] ^ set[a]), 16); set[c] = unchecked (set[c] + set[d]); set[b] = BitShift.RotateLeft32(unchecked (set[b] ^ set[c]), 12); set[a] = unchecked (set[a] + set[b]); set[d] = BitShift.RotateLeft32(unchecked (set[d] ^ set[a]), 8); set[c] = unchecked (set[c] + set[d]); set[b] = BitShift.RotateLeft32(unchecked (set[b] ^ set[c]), 7); }
public Node ExprBitShift() { Node expressionAdd = ExprAdd(); while (bitShiftOperators.Contains(CurrentToken)) { Node expressionBitShift = new BitShift() { AnchorToken = OpBitShift() }; expressionBitShift.Add(expressionAdd); expressionBitShift.Add(ExprAdd()); return(expressionBitShift); } return(expressionAdd); }
public void ProcessingRightTest() { // given: test image using (var img = TestHelper.CreateMonoTestImage(new byte[] { 0, 1, 10, 255 })) { var p = new BitShift() { ShiftDirection = BitShiftDirection.Right }; p.ValueProvider.FixedValue = 1; // when: applying the processor using (var processedImage = p.Process(img)) { // then: pixels bit shifted CollectionAssert.AreEqual(new byte[] { 0, 0, 5, 127 }, processedImage.GetPixels()); } } }