public void Encode_and_decode_text_to_bitmap() { var text = "Some text that i want to pass through"; var bitmap = new Bitmap(50, 50); LSB.Encode(bitmap, text); var decoded = LSB.Decode(bitmap); Assert.AreEqual(text, decoded); }
public void All_together_now() { var text = "Some text that i want to pass through"; var key = Guid.NewGuid(); var bitmap = new Bitmap(50, 50); var encrypted = Crypter.Encrypt(text, key); LSB.Encode(bitmap, encrypted); var decoded = LSB.Decode(bitmap); var decrypted = Crypter.Decrypt(decoded, key); Assert.AreEqual(text, decrypted); }
public virtual void OnView() { var pixels = this.Texture2D.GetPixels32(); LSB.Decode(pixels, (code, data) => { if (code == LSB.Code.Error) { Debug.LogError("Could not decode message!"); return; } var message = System.Text.Encoding.UTF8.GetString(data); int index = -1; for (int i = 0; i < message.Length; ++i) { // sanity check of when transmission // fails (don't know why don't care) if (message[i] == ']') { if ((i + 1) < message.Length) { if (message[i + 1] == '|' && message[i + 2] == '[') { index = i; break; } } else { index = -1; } } } if (index == -1) { return; } message = message.Substring(0, index); Dialog.Show(message); }); }
private void Decrypt(object sender, RoutedEventArgs routedEventArgs) { if (string.IsNullOrWhiteSpace(KeyInput.Text)) { TextInput.Text = LSB.Decode(bitmap); StatusLabel.Content = "Decrypted without key"; } else if (Guid.TryParse(KeyInput.Text.Trim(), out var guid)) { var text = LSB.Decode(bitmap); TextInput.Text = Crypter.Decrypt(text, guid); StatusLabel.Content = "Decrypted with given key"; } else { StatusLabel.Content = "Invalid key"; } }