public MainWindow() { InitializeComponent(); int[] baudRate = {4800, 9600, 19200, 38400, 57600, 115200, 230400}; BaudrateComboBox.ItemsSource = baudRate; BaudrateComboBox.SelectedValue = baudRate[2]; FirmwareFilenameTextBox.Text = FileNotSelectedText; InitializeFormValues(); ReadSettings(); Closed += OnClosed; _vioCrypt = new VioCrypt(); }
public void TestVioCrypt() { byte[] cryptTable = LoadTable("crypt.bin", "can't load crypt table"); byte[] decryptTable = LoadTable("decrypt.bin", "can't load decrypt table"); var testObject = new VioCrypt {CryptTable = cryptTable, DecryptTable = decryptTable}; Assert.IsNotNull(testObject.DecryptTable); Assert.IsNotNull(testObject.CryptTable); var testBytearray = new byte[0x10000]; var cryptedBytearray = new byte[0x10000]; var decryptedBytearray = new byte[0x10000]; var rnd = new Random((int) DateTime.Now.Ticks); for (var idx = 0; idx < testBytearray.Length; ++idx) testBytearray[idx] = (byte) rnd.Next(0, 0x100); const int packetLen = 0x20; var packetCount = testBytearray.Length / packetLen; testObject.ResetCryptState(); var internalBuffer = new byte[packetLen]; // шифруем for (var packetNum = 0; packetNum < packetCount; ++packetNum) { Array.Copy(testBytearray, packetNum * packetLen, internalBuffer, 0, packetLen); var result = testObject.ContinueCrypt(internalBuffer); Array.Copy(result, 0, cryptedBytearray, packetNum * packetLen, packetLen); } // обратная операция testObject.ResetCryptState(); for (var packetNum = 0; packetNum < packetCount; ++packetNum) { Array.Copy(cryptedBytearray, packetNum * packetLen, internalBuffer, 0, packetLen); var result = testObject.ContinueDecrypt(internalBuffer); Array.Copy(result, 0, decryptedBytearray, packetNum * packetLen, packetLen); } for (var idx = 0; idx < testBytearray.Length; ++idx) { Assert.AreEqual(testBytearray[idx], decryptedBytearray[idx], "error on index: " + idx); } }