public void TestEncode() { byte[] message = UTF8Encoding.UTF8.GetBytes("hello world"); string expected_header = "header-part "; string expected_footer = " footer part."; string expected_result = expected_header + Base58CheckEncoding.Encode(message) + expected_footer; SimplePack packer = new SimplePack(expected_header, expected_footer); string actual_result = packer.encode(message); Assert.AreEqual(actual_result, expected_result); }
public void TestDecode() { byte[] expected_result = UTF8Encoding.UTF8.GetBytes("hello world"); string header = "header-part "; string footer = " footer part."; string encoded = header + Base58CheckEncoding.Encode(expected_result) + footer; SimplePack packer = new SimplePack(header, footer); Assert.AreEqual(packer.decode(encoded), expected_result); }
public void TestInvalidChecksum() { byte[] expected_result = UTF8Encoding.UTF8.GetBytes("hello world"); string header = "header-part "; string footer = " footer part."; string encoded = header + Base58CheckEncoding.EncodePlain(expected_result) + footer; SimplePack packer = new SimplePack(header, footer); try{ packer.decode(encoded); } catch (System.FormatException) { return; } Assert.Fail(); // Did not catch no checksum, fail }
public void TestRequireFooter() { string header = "test-header"; string footer = ""; byte[] expected_result = UTF8Encoding.UTF8.GetBytes("hello world"); string encoded = header + Base58CheckEncoding.Encode(expected_result) + footer; try{ SimplePack packer = new SimplePack(header, footer); } catch (InvalidSimplePackHeader) { return; } Assert.Fail(); }
private async void MenuItem_Click(object sender, RoutedEventArgs e) { SimplePack pack = (SimplePack)dataGrid.SelectedItem; int index = Model.BotCollection.IndexOf(pack.Name); botListComboBox.SelectedIndex = index; await PerformSearch(async() => { if (botListComboBox.SelectedIndex == 0) { await _searchService.SearchBotsDeepAsync(searchTextBox.Text, size: 25, ascendingSort: GetAscOrDescSort(), orderby: GetOrderBySort()); } else { await _searchService.SearchBotsDeepAsync(searchTextBox.Text, botId: (int?)_searchService.GetBotIdFromName(pack.Name), size: 25, ascendingSort: GetAscOrDescSort(), orderby: GetOrderBySort()); } }); }
public Task AddToQueue(SimplePack pack) { DownloadQueueList.Add(pack); return(Task.CompletedTask); }
static void Main(string[] args) { RC4Encryption rc4Server = new RC4Encryption(); RC4Encryption rc4Client = new RC4Encryption(); rc4Server.makeSBox("zhangyawei"); rc4Client.makeSBox("zhangyawei"); IntegerData idata = new IntegerData('a', 1, 5, 20, 30, 40, 50, 60); FloatData fdata = new FloatData(243.123123f, 32432.123); StringData sdata = new StringData("love"); EchoPack pack = new EchoPack(); pack._iarray = new IntegerDataArray(); pack._iarray.Add(idata); pack._iarray.Add(idata); pack._iarray.Add(idata); pack._farray = new FloatDataArray(); pack._farray.Add(fdata); pack._farray.Add(fdata); pack._farray.Add(fdata); pack._sarray = new StringDataArray(); pack._sarray.Add(sdata); pack._sarray.Add(sdata); pack._sarray.Add(sdata); pack._imap = new IntegerDataMap(); pack._imap.Add("123", idata); pack._imap.Add("223", idata); pack._fmap = new FloatDataMap(); pack._fmap.Add("523", fdata); pack._fmap.Add("623", fdata); pack._smap = new StringDataMap(); pack._smap.Add("723", sdata); pack._smap.Add("823", sdata); var now = DateTime.UtcNow; for (int i = 0; i < 1; i++) { var byteData = pack.__encode(); var binData = byteData.ToArray(); // for (int i = 0; i < binData.Length; i++) // { // System.Console.WriteLine((int)binData[i]); // } rc4Server.encryption(binData, binData.Length); rc4Client.encryption(binData, binData.Length); // for (int i = 0; i < binData.Length; i++) // { // System.Console.WriteLine((int)binData[i]); // } var v = new EchoPack(); int pos = 0; v.__decode(binData, ref pos); try { SimplePack pk = new SimplePack(10, "name", 100, null); pk.moneyTree = new MoneyTree(10001, 5, 5, 0, 0); var binMemory = pk.__encode().ToArray(); //序列化 SimplePack recvPK = new SimplePack(); int curPos = 0; recvPK.__decode(binMemory, ref curPos); System.Console.Write("success"); } catch (Exception e) { System.Console.Write("error"); } Client client = new Client(); client.Run(binData); } System.Console.WriteLine(DateTime.UtcNow - now); }