public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) { int returnCount = inputCount; this.LengthCipher += inputCount; for (int i = 0; i < inputCount; i += OutputBlockSize) { IncrementCounter(); byte[] iBuffer = new byte[InputBlockSize]; byte[] oBuffer = new byte[OutputBlockSize]; Array.Copy(inputBuffer, inputOffset + i, iBuffer, 0, InputBlockSize); this.Aes.Encrypt(Counter, 0, oBuffer, 0); oBuffer = iBuffer.Add(oBuffer); if (Encrypt) { ByteTag = GaloisMultiplication.GMul128(oBuffer.Add(ByteTag), H); } else { ByteTag = GaloisMultiplication.GMul128(iBuffer.Add(ByteTag), H); } Array.Copy(oBuffer, 0, outputBuffer, outputOffset + i, OutputBlockSize); } return(returnCount); }
public int SetCalibrationValue(byte type, byte cmd, short value) { byte[] data = new byte[4]; int offset = 0; //data.Add(ref offset, BitConverter.GetBytes(type)); //data.Add(ref offset, BitConverter.GetBytes(cmd)); //data.Add(ref offset, BitConverter.GetBytes(value)); data.Add(ref offset, type); data.Add(ref offset, cmd); data.Add(ref offset, BitConverter.GetBytes(value)); V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdHandleCalibration, data, sender, receiver); V45Packet ret = SendMessage(cmdPack); return(ret.Payload[0]); //SendMessage(cmdPack); //if (ret.Payload[0]==0) //{ // return 0; //} //else //{ // return 1; //} //return BitConverter.ToInt32(ret.Payload, 2); //return BitConverter.ToUInt16(ret.Payload, 0); }
public byte[] GetEncoded(bool compressed = true) { if (curve.IsInfinity(this)) { return(new byte[] { 0 }); // Infinity point encoded is simply '00' } var affineX = AffineX; var affineY = AffineY; var buffer = new byte[0]; var byteLength = ( int )Math.Floor((curve.P.BitLength + 7) / 8.0); if (compressed) // 0x02/0x03 | X { buffer = buffer.Add(( byte )(affineY.IsEven ? 0x02 : 0x03)); buffer = buffer.Concat(affineX.ToBuffer(byteLength)); } else // 0x04 | X | Y { buffer = buffer.Add(( byte )0x04); buffer = buffer.Concat(affineX.ToBuffer(byteLength)); buffer = buffer.Concat(affineY.ToBuffer(byteLength)); } return(buffer); }
public byte[] Encode() { byte[] data = new byte[24]; int offset = 0; data.Add(ref offset, BitConverter.GetBytes(Flow)); data.Add(ref offset, BitConverter.GetBytes(Pressure)); data.Add(ref offset, BitConverter.GetBytes(Volume)); return(data); }
public Boolean BottonPress(UInt16 buttonNumber) { byte[] data = new byte[3]; int offset = 0; data.Add(ref offset, BitConverter.GetBytes(buttonNumber)); data.Add(ref offset, 1);//Pressed V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdButtonPress, data, sender, receiver); var packet = SendMessage(cmdPack); return(Convert.ToBoolean(packet.Payload[0])); }
public Boolean SetAlarm(byte alarm, byte active) { byte[] data = new byte[3]; int offset = 0; data.Add(ref offset, alarm); data.Add(ref offset, active);//Pressed V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdSetAlarm, data, sender, receiver); var packet = SendMessage(cmdPack); return(Convert.ToBoolean(packet.Payload[0])); }
public bool VerifyChallengeString(byte[] challengeString) { byte[] data = new byte[challengeString.Length + sizeof(UInt16)]; int offset = 0; data.Add(ref offset, BitConverter.GetBytes((UInt16)challengeString.Length)); data.Add(ref offset, challengeString); V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdVerifyChallengeString, data, sender, receiver); var packet = SendMessage(cmdPack); return(Convert.ToBoolean(packet.Payload[0])); }
public bool SetEncryptionKey(byte[] key) { byte[] data = new byte[key.Length + sizeof(byte)]; int offset = 0; data.Add(ref offset, Convert.ToByte(key.Length)); data.Add(ref offset, key); V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdSetEncryptionKey, data, sender, receiver); var packet = SendMessage(cmdPack); return(packet.Payload.Length == data.Length); }
public ushort GetSettingValue(byte profile, byte type, ushort settingId) { byte[] data = new byte[4]; int offset = 0; data.Add(ref offset, profile); data.Add(ref offset, BitConverter.GetBytes(settingId)); data.Add(ref offset, type); V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdGetSetting, data, sender, receiver); var ret = SendMessage(cmdPack); return(BitConverter.ToUInt16(ret.Payload, 4)); }
public void ShouldThrowExceptionIfByteArrayBLongerthanByteArrayA() { var bArrayA = new byte[] { 1 }; var bArrayB = new byte[] { 1, 2 }; Assert.Throws(typeof(ArgumentException), () => bArrayA.Add(bArrayB)); }
public string SendWifiCommand(string cmd) { byte[] data = new byte[System.Text.Encoding.UTF8.GetByteCount(cmd) + 1]; //+1 for null termination int offset = 0; data.Add(ref offset, System.Text.Encoding.UTF8.GetBytes(cmd)); data.Add(ref offset, 0); //null termination V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdHandleWifi, data, sender, receiver); var packet = SendMessage(cmdPack); return(System.Text.Encoding.UTF8.GetString(packet.Payload, 0, packet.PayloadLength)); }
public SubscriptionResult UnSubscribeToMeasurepoints(List <UInt16> measurePoints) { try { byte[] data = new byte[3 + (2 * measurePoints.Count)]; data[0] = 3; data[1] = 1; data[2] = Convert.ToByte(measurePoints.Count); int i = 0; int offset = 3; while (i < 10 && i < measurePoints.Count) { data.Add(ref offset, BitConverter.GetBytes(measurePoints[i])); i++; } V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdHandleMeasurePointSub, data, this.sender, this.receiver); V45Packet responsePack = SendMessage(cmdPack); return(new SubscriptionResult(responsePack.Payload)); } catch (DisconnectedException e) { if (communication.Connect()) { return(UnSubscribeToMeasurepoints(measurePoints)); } else { throw e; } } }
public int SetMeasurePointValue(ushort id, uint value) { byte[] data = new byte[6]; int offset = 0; data.Add(ref offset, BitConverter.GetBytes(id)); data.Add(ref offset, BitConverter.GetBytes(value)); V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdSetMeasPointValue, data, sender, receiver); V45Packet ret = SendMessage(cmdPack); //return BitConverter.ToInt32(ret.Payload, 2); return(1); }
public bool CopyProfile(byte sourceProfile, byte destinationProfile) { byte[] data = new byte[2]; int offset = 0; data.Add(ref offset, sourceProfile); data.Add(ref offset, destinationProfile); V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdCopyProfile, data, sender, receiver); var ret = SendMessage(cmdPack); return(Convert.ToBoolean(ret.Payload[0])); }
public bool ChangeProfileName(byte ProfileId, string profileName) { byte[] data = new byte[13]; for (int i = 0; i < data.Length; i++) { data[i] = 0; } int offset = 0; data.Add(ref offset, ProfileId); data.Add(ref offset, System.Text.Encoding.UTF8.GetBytes(profileName)); V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdSetProfileName, data, sender, receiver); var ret = SendMessage(cmdPack); return(Convert.ToBoolean(ret.Payload[0])); }
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount) { this.LengthCipher += inputCount; byte[] output = new byte[inputCount]; byte[] oBuffer = new byte[OutputBlockSize]; if (inputCount > 0) { IncrementCounter(); byte[] iBuffer = new byte[InputBlockSize]; Array.Copy(inputBuffer, inputOffset, iBuffer, 0, InputBlockSize); this.Aes.Encrypt(Counter, 0, oBuffer, 0); oBuffer = iBuffer.Add(oBuffer); if (Encrypt) { Array.Clear(oBuffer, inputCount, oBuffer.Length - inputCount); ByteTag = GaloisMultiplication.GMul128(oBuffer.Add(ByteTag), H); } else { ByteTag = GaloisMultiplication.GMul128(iBuffer.Add(ByteTag), H); } Array.Copy(oBuffer, 0, output, 0, inputCount); } byte[] length = ConvertToByteArray(AdditionalData.Length * 8, LengthCipher * 8); ByteTag = GaloisMultiplication.GMul128(ByteTag.Add(length), H); this.Aes.Encrypt(InitialCounter, 0, oBuffer, 0); ByteTag = oBuffer.Add(ByteTag); if (Encrypt) { SetTag(); } else { AssertAuthentication(); } return(output); }
/// <summary> /// GS k m n /// </summary> public static byte[] PrintBarCode(BarCodeType barCodeType, string barCode, int heightInDots = 162) { var height = new byte[] { 0x1D, 0x68, (byte)heightInDots }; var settings = new byte[] { 0x1D, 0x6B, (byte)barCodeType, (byte)barCode.Length }; var bar = Encoding.UTF8.GetBytes(barCode); return(height.Add(settings, bar)); }
private V45Packet HandleLogData(Vivo45LogPacket.Vivo45LogAction action, Vivo45LogPacket.Vivo45LogLevel level, DateTime startTimestamp, DateTime endTimestamp, bool storeSync) { byte[] data = new byte[11]; int offset = 0; data.Add(ref offset, Convert.ToByte(action)); data.Add(ref offset, Convert.ToByte(level)); data.Add(ref offset, BitConverter.GetBytes(GetEpochSecondsFromDateTime(startTimestamp))); data.Add(ref offset, BitConverter.GetBytes(GetEpochSecondsFromDateTime(endTimestamp))); data.Add(ref offset, Convert.ToByte(storeSync)); V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdHandleLogData, data, sender, receiver); var packet = SendMessage(cmdPack); return(packet); }
public ChangeSettingResult SetSetting(byte profile, byte type, ushort settingId, ushort value) { byte[] data = new byte[6]; int offset = 0; data.Add(ref offset, profile); data.Add(ref offset, BitConverter.GetBytes(settingId)); data.Add(ref offset, type); data.Add(ref offset, BitConverter.GetBytes(value)); V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdSetSetting, data, sender, receiver); //var ret = SendMessage1(cmdPack); var ret = SendMessage(cmdPack); ChangeSettingResult changesettingresult = new ChangeSettingResult(ret.Payload); return(changesettingresult); }
private byte[] FinalDecrypt(byte[] input, byte[] key) { byte[] output = new byte[input.Length]; output = InverseShiftRows(input); output = ByteInverseSubstitution(output); output = output.Add(key); return(output); }
public void AddsColor(byte r1, byte g1, byte b1, byte a1, byte r2, byte g2, byte b2, byte a2) => Color.FromArgb(a1, r1, g1, b1) .Add(Color.FromArgb(a2, r2, g2, b2)) .Should().Be(Color.FromArgb(a1.Add(a2), r1.Add(r2), g1.Add(g2), b1.Add(b2)));
/// <summary> /// 3: For i = 1; i <= n; i++ /// Xi = (Xi-1 XOR IV) * H /// 4: T = (Xn XOR (0 || length(IV))) * H /// </summary> /// <param name="H"></param> /// <param name="IV"></param> /// <returns></returns> private byte[] GHashIV(byte[] H, byte[] IV) { int blocks = IV.Length / 16; blocks += IV.Length % 16 == 0 ? 1 : 2; byte[] temp = new byte[OutputBlockSize]; for (int i = 1; i < blocks; i++) { byte[] IVBlock = new byte[OutputBlockSize]; int cpLength = IV.Length - ((i - 1) * 16); cpLength = cpLength > 16 ? 16 : cpLength; Array.Copy(IV, (i - 1) * 16, IVBlock, 0, cpLength); temp = GaloisMultiplication.GMul128(temp.Add(IVBlock), H); } return(GaloisMultiplication.GMul128(temp.Add(ConvertToByteArray(IV.Length * 8)), H)); }
public Boolean StartBuzzer() { byte[] data = new byte[6]; int offset = 0; data.Add(ref offset, 0); data.Add(ref offset, 0); UInt32 time = 1000; data.Add(ref offset, BitConverter.GetBytes(time)); //Time //data.Add(ref offset, 5); //Volume V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdTestBuzzer, data, sender, receiver); var packet = SendMessage(cmdPack); return(Convert.ToBoolean(packet.Payload[0])); }
protected virtual byte[] EncryptRound(byte[] input, byte[] key) { byte[] output = new byte[input.Length]; output = ByteSubstitution(input); output = ShiftRows(output); output = MixColumns(output); output = output.Add(key); return(output); }
private byte[] DecryptRound(byte[] input, byte[] key) { byte[] output = new byte[input.Length]; output = InverseShiftRows(input); output = ByteInverseSubstitution(output); output = output.Add(key); output = InverseMixColumns(output); return(output); }
public Boolean SetDeviceInfoValue(UInt16 id, string str) { byte[] data = new byte[2 + System.Text.Encoding.UTF8.GetBytes(str).Length + 1]; //Add one for null termination for (int i = 0; i < data.Length; i++) { data[i] = 0; } int offset = 0; data.Add(ref offset, BitConverter.GetBytes(id)); data.Add(ref offset, System.Text.Encoding.UTF8.GetBytes(str)); V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdSetDeviceValue, data, sender, receiver); var packet = SendMessage(cmdPack); return(Convert.ToBoolean(packet.Payload[0])); }
public Boolean MuteSpeaker() { byte[] data = new byte[7]; int offset = 0; data.Add(ref offset, 1); //Speaker data.Add(ref offset, 1); //Action UInt32 time = 30000; data.Add(ref offset, BitConverter.GetBytes(time)); //Time data.Add(ref offset, 1); //Volume V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdTestBuzzer, data, sender, receiver); var packet = SendMessage(cmdPack); return(Convert.ToBoolean(packet.Payload[0])); }
public byte[] TestImage() { Reciept = new byte[0]; Reciept = Reciept .Add(Getlogo(Model.Firma.Bitmap, ImageMultiplier), Getlogo(GetFromResource("MainTest.jpeg"), ImageMultiplier), CarriageReturn, CarriageReturn, CarriageReturn); return(Reciept); }
public void Encrypt(byte[] inputBuffer, int inputOffset, byte[] outputBuffer, int outputOffset) { byte[] buffer = new byte[InputBlockSize]; Array.Copy(inputBuffer, inputOffset, buffer, 0, InputBlockSize); buffer = buffer.Add(RoundKey[0]); for (int round = 1; round < NumberOfRounds(); round++) { buffer = EncryptRound(buffer, RoundKey[round]); } buffer = FinalEncrypt(buffer, RoundKey[NumberOfRounds()]); Array.Copy(buffer, 0, outputBuffer, outputOffset, OutputBlockSize); }
public int GetMeasurePointValue(ushort id) { byte[] data = new byte[2]; int offset = 0; data.Add(ref offset, BitConverter.GetBytes(id)); V45Packet cmdPack = new V45Packet(V45Packet.V45Commands.cmdGetMeasPointValue, data, this.sender, this.receiver); V45Packet ret = SendMessage(cmdPack); return(BitConverter.ToInt32(ret.Payload, 2)); }