public void Set_and_check_watermark() { var bitmap = new Bitmap(50, 50); LSB.SetWatermark(bitmap); Assert.True(LSB.CheckWatermark(bitmap)); }
public string ToXMLstring() { string res = ""; if (IsComment) { res += "<tr bgcolor = 'green'>"; } else if (!IsValid) { res += "<tr bgcolor = 'red'>"; } else { res += "<tr>"; } res += "<td>" + Name; res += "</td><td>" + Group; res += "</td><td>" + Address.ToString(); res += "</td><td>" + MAIS.ToString(); res += "</td><td>" + LSB.ToString(); res += "</td><td>" + MSB.ToString(); res += "</td><td>" + valid_type[(int)Type]; res += "</td><td>" + valid_fpga[(int)FPGA]; res += "</td><td>" + Init; res += "</td><td>" + Comment + "</td></tr>"; return(res); }
private void decode_button_Click(object sender, RoutedEventArgs e) { Decode_SetDefaultColors(); switch (decode_select.SelectedIndex) { case 0: MessageBox.Show("Выберите тип кодирования"); break; case 1: if (!Decode_CheckValidate()) { MessageBox.Show("Введены неверные данные\nИсправьте выделенные пути файлов"); break; } LSB.Extract(decode_outputdirectorytext.Text, decode_password.Password, decode_audiofile.Text); break; case 2: if (!Decode_CheckValidate()) { MessageBox.Show("Введены неверные данные\nИсправьте выделенные пути файлов"); break; } ParityMethod.Extract(decode_outputdirectorytext.Text, decode_audiofile.Text); break; case 3: decode_output.Text = PhaseCoding.PhaseCoding.Extract(decode_outputdirectorytext.Text, decode_password.Password, decode_audiofile.Text); break; } }
/// <summary> /// Compares that current instance with another object of the same type. /// </summary> /// <param name="that">An object to compare with this instance.</param> /// <returns> /// A value that indicates the relative order of the objects being compared. /// The return value has these meanings: /// <list type="table"> /// <listheader> /// <term>Value</term> /// <description>Meaning</description> /// </listheader> /// <item> /// <term>Less than zero</term> /// <description>This instance precedes other in the sort order.</description> /// </item> /// <item> /// <term>Zero</term> /// <description>This instance occurs in the same position in the sort order as other.</description> /// </item> /// <item> /// <term>Greater than zero</term> /// <description>This instance follows other in the sort order.</description> /// </item> /// </list> /// </returns> public int CompareTo(UUID that) { if (MSB < that.MSB) { return(-1); } return(MSB > that.MSB ? 1 : LSB.CompareTo(that.LSB)); }
private void Encode(string text) { LSB.Encode(bitmap, text); LSB.SetWatermark(bitmap); MainImage.Source = Convert(bitmap); SaveButton.IsEnabled = true; }
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 string ToEntry(bool last = false) { string res = ""; if (IsComment) { res += "--"; } if (Type == type_field.FIELD) { res += "\t\t\t\t\t" + "(" + Name + getSpaces(35 - Name.Length) + ","; } else { res += "\t\t\t\t" + "(" + Name + getSpaces(39 - Name.Length) + ","; } string adrs = Address.ToString(); res += getSpaces(8 - adrs.Length) + adrs + ","; res += " " + MAIS.ToString() + ","; string lsb = LSB.ToString(); string msb = MSB.ToString(); res += getSpaces(3 - lsb.Length) + lsb + "," + getSpaces(3 - msb.Length) + msb + ","; res += " " + valid_type[(int)Type] + getSpaces(5 - valid_type[(int)Type].Length) + ","; res += " " + valid_fpga[(int)FPGA] + getSpaces(4 - valid_fpga[(int)FPGA].Length) + ","; if (int.TryParse(Init, out int x)) { res += getSpaces(Math.Max(4 - Init.Length, 0)) + Init + ")"; } else { res += Init + ")"; } if (!last) { res += ","; } if (Comment != "") { res += "\t-- " + Comment; } res += "\n"; return(res); }
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 static void Decode(Color32[] colors, System.Action <Code, byte[]> onComplete) { uThread.RunTaskAsync( () => { List <byte> data = new List <byte>(); byte[] color = new byte[3]; int bit_index = 0; byte result = 0; byte lsb = 1 << 0; // Extract data... for (int i = 0; i < colors.Length; ++i) { color[0] = colors[i].r; color[1] = colors[i].g; color[2] = colors[i].b; for (int j = 0; j < 3; ++j) { unchecked { result = (byte)((result << 1) | color[j] & lsb); } bit_index++; if (bit_index == 8) { bit_index = 0; // this is a poor way of checking if we are done...but lets do it? if (result == 0) { uThread.RunOnUnityThread(() => { onComplete?.Invoke(Code.Success, data.ToArray()); }); return; } else { result = LSB.Reverse(result); data.Add(result); } } } } }); }
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); }); }
public virtual void Encode() { var pixels = this.picture.GetPixels32(); var message = this.message + "]|["; LSB.Encode(pixels, System.Text.Encoding.UTF8.GetBytes(message), (code) => { if (code == LSB.Code.Success) { var result = new Texture2D(this.picture.width, this.picture.height); result.SetPixels32(pixels); this.onEncodeEvent.Invoke(result); } }); }
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"; } }
// функция вызова первого метода public void Method1_LSB() { labelAttention.Text = ""; if (bMap == null) { labelAttention.Text = "Вставьте изображение!"; // проверка на наличие изображения } else { if (textBox1.Text != "") // проверка на наличие текста { var result = LSB.IsHiddenText(bMap, out Colours c); // содержится ли скрытый текст if (!result || Attention(result)) // если нет скрытого текста или пользователь все равно хочет заменить его на новый { try { Colours colour = (Colours)ColourBox1.SelectedIndex; // цвет задаем в соответвии с выбранным в comboBox1, приводя к перечислению Colours bMapSteg = LSB.Hide(bMap, textBox1.Text, colour); // создаем новый объект StegoBitmap, хранящий в себе скрытый текст pictureBox2.Image = bMapSteg.GetImage(); // задаем изображение в pictureBox2 } catch (NullReferenceException) { string message = "Не выбран цвет для сокрытия текста"; string caption = "Отсутствие цвета"; MessageBoxButtons button = MessageBoxButtons.OK; DialogResult res = MessageBox.Show(message, caption, button); // отобразить MessageBox } catch (Exception) { labelAttention.Text = "Что-то пошло не так, попробуйте позже"; //в случае какой-то неполадки } } } else { labelAttention.Text = "Введите текст!"; // при отсутствии текста } } }
private void OpenFileButton_Click(object sender, RoutedEventArgs e) { var openFileDialog = new OpenFileDialog { CheckFileExists = true, CheckPathExists = true, Filter = FileFilter }; if (openFileDialog.ShowDialog() == true) { bitmap = (Bitmap)Image.FromFile(openFileDialog.FileName); MainImage.Source = new BitmapImage(new Uri(openFileDialog.FileName)); WatermarkLabel.Text = LSB.CheckWatermark(bitmap) ? "✔ Image may has encrypted text" : "❌ Image has no encrypted text"; EncryptButton.IsEnabled = true; DecryptButton.IsEnabled = true; SaveButton.IsEnabled = false; } }
public static void Encode(Color32[] pixels, byte[] data, System.Action <Code> onComplete, System.Action <float> onProgress = null) { // Conduct calculations // on an other thread... uThread.RunTaskAsync(() => { byte[] color = new byte[3]; int total_bits = pixels.Length * 3; int bits_for_message = data.Length * 8; if ((bits_for_message + 8) >= total_bits) { onComplete?.Invoke(Code.Error); return; } // copy RGB values // for ease of access color[0] = pixels[0].r; color[1] = pixels[0].g; color[2] = pixels[0].b; int color_index = 0; int pixel_index = 0; int bit_index = -1; int byte_index = -1; byte bite = 0; byte padding_value = 0; // Encoding data into colors... for (int i = 0; i < bits_for_message; ++i) { onProgress?.Invoke((float)(i + 1) / (bits_for_message + 8)); bit_index++; if (bit_index % 8 == 0) { bit_index = 0; bite = data[++byte_index]; } LSB.Set(bite, ref color[color_index]); bite = (byte)(bite >> 1); color_index = (color_index + 1) % 3; if (color_index == 0) { pixels[pixel_index].r = color[0]; pixels[pixel_index].g = color[1]; pixels[pixel_index].b = color[2]; pixel_index++; color[0] = pixels[pixel_index].r; color[1] = pixels[pixel_index].g; color[2] = pixels[pixel_index].b; } } // padding... for (int i = 0; i < 8; ++i) { onProgress?.Invoke((float)(i + 1 + bits_for_message) / (bits_for_message + 8)); // we are now padding... LSB.Set(padding_value, ref color[color_index]); color_index = (color_index + 1) % 3; if (color_index == 0) { pixels[pixel_index].r = color[0]; pixels[pixel_index].g = color[1]; pixels[pixel_index].b = color[2]; pixel_index++; color[0] = pixels[pixel_index].r; color[1] = pixels[pixel_index].g; color[2] = pixels[pixel_index].b; } } uThread.RunOnUnityThread(() => { onComplete?.Invoke(Code.Success); }); }); }
// кнопка 'DECODE' private void button4_Click(object sender, EventArgs e) { labelAttention.Text = ""; if (bMap == null) { labelAttention.Text = "Вставьте изображение!"; // проверка на наличие изображения } else { if (methodButton1.Checked) // проверка по методу LSB { try { if (LSB.IsHiddenText(bMap, out Colours c)) { textBox1.Text = LSB.GetHiddenText(bMap, c); // получаем и выводим скрытый текст labelAttention.Text = "Скрытый текст найден"; } else { labelAttention.Text = "В изображении отсутствует скрытый текст по данному методу";// отсутствие скрытого текста } } catch (Exception) { labelAttention.Text = "Что-то пошло не так, попробуйте позже"; //в случае какой-то неполадки } } else if (methodButton2.Checked) // проверка по методу Коха-Жао { try // проверка на выбор цвета { Colours colour = (Colours)ColourBox2.SelectedIndex; // цвет задаем в соответвии с выбранным в comboBox1, приводя к перечислению Colours textBox1.Text = KochZhao.GetHiddenText(bMap, colour); // получаем и выводим скрытый текст if (textBox1.Text != "") { labelAttention.Text = "Скрытый текст найден"; } else { labelAttention.Text = "В изображении отсутствует скрытый текст по данному методу";// отсутствие скрытого текста } } catch (NullReferenceException) { string message = "Проверка по методу Коха-Жао. Выберите цвет для выявления текста в разделе соответствующего метода"; string caption = "Отсутствие цвета"; MessageBoxButtons button = MessageBoxButtons.OK; DialogResult diaRes = MessageBox.Show(message, caption, button); // отобразить MessageBox } catch (Exception) { labelAttention.Text = "Что-то пошло не так, попробуйте позже"; //в случае какой-то неполадки } } else if (methodButton3.Checked) // проверка по методу Бенгама { try // проверка на выбор цвета { Colours colour = (Colours)ColourBox3.SelectedIndex; // цвет задаем в соответвии с выбранным в comboBox3, приводя к перечислению Colour textBox1.Text = Benham.GetHiddenText(bMap, colour); // получаем и выводим скрытый текст if (textBox1.Text != "") { labelAttention.Text = "Скрытый текст найден"; } else { labelAttention.Text = "В изображении отсутствует скрытый текст по данному методу";// отсутствие скрытого текста } } catch (NullReferenceException) { string message = "Проверка по методу Бенгама. Выберите цвет для выявления текста в разделе соответствующего метода"; string caption = "Отсутствие цвета"; MessageBoxButtons button = MessageBoxButtons.OK; DialogResult res = MessageBox.Show(message, caption, button); // отобразить MessageBox } catch (Exception) { labelAttention.Text = "Что-то пошло не так, попробуйте позже"; //в случае какой-то неполадки } } else { labelAttention.Text = "Не выбран метод для поиска текста в изображении"; } } }
private void StartDecodeButton_MouseDown(object sender, MouseButtonEventArgs e) { LSB.DecodeImage(_sourcePath, _resultPath); MessageBox.Show("Finished!", "Result", MessageBoxButtons.OK); }
private void EncodeButton_MouseDown(object sender, MouseButtonEventArgs e) { _resultFolderPath = FileSystemDialog.SelectFolder(); LSB.EncodeImage(_sourceImagePath, _sourceTextPath, _resultFolderPath); MessageBox.Show("Finished!", "Result", MessageBoxButtons.OK); }
public virtual void GameEvents_OnUpdateTick(object sender, EventArgs e) { if (Player.usingTool && Player.CurrentTool is FishingRod && Rod.isFishing) { if (!Fishing) { Fishing = true; Configs.Bait = null; if (Rod.attachments?.Length > 0 && Rod.attachments[0] != null) { LoadBaitConfig(Rod.attachments[0].parentSheetIndex); } Configs.Tackle = null; if (Rod.attachments?.Length > 1 && Rod.attachments[1] != null) { LoadTackleConfig(Rod.attachments[1].parentSheetIndex); } Vector2 BobberLocation = (Vector2)typeof(FishingRod).GetField("bobber", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance).GetValue(Rod); Point SplashPoint = Location.fishSplashPoint; Rectangle rectangle = new Rectangle(Location.fishSplashPoint.X * Game1.tileSize, Location.fishSplashPoint.Y * Game1.tileSize, Game1.tileSize, Game1.tileSize); if (new Rectangle((int)BobberLocation.X - Game1.tileSize * 5 / 4, (int)BobberLocation.Y - Game1.tileSize * 5 / 4, Game1.tileSize, Game1.tileSize).Intersects(rectangle)) { BobberIsOnFishingPoint = true; } else { BobberIsOnFishingPoint = false; } Configs.AppliedLocationEffects.Clear(); foreach (LocationSettingsBoundary LSB in Configs.LocationSettings.LocationSettings) { if (LSB.WithinBoundary(Game1.currentLocation, BobberLocation)) { Configs.AppliedLocationEffects.Add(LSB.Settings); } } float minTime = Configs.GeneralSettings.MinTimeUntilBite; minTime += BobberIsOnFishingPoint ? Configs.FishingPoint.MinTimeUntilBiteAdditive : 0; minTime += DailyLuck * Configs.DailyLuck.MinTimeUntilBiteAdditive; minTime += LuckLevel * Configs.PlayerLuck.MinTimeUntilBiteAdditive; minTime += FishingLevel == 0 ? 0 : (FishingLevel * Configs.FishingLevel.MinTimeUntilBiteAdditive); minTime += Configs.Bait == null ? 0 : Configs.Bait.MinTimeUntilBiteAdditive; minTime += Configs.Tackle == null ? 0 : Configs.Tackle.MinTimeUntilBiteAdditive; foreach (LocationSettingsData LSD in Configs.AppliedLocationEffects) { minTime += LSD.MinTimeUntilBiteAdditive; } minTime *= BobberIsOnFishingPoint ? Configs.FishingPoint.MinTimeUntilBiteMultiplier : 1; minTime *= (1 + (DailyLuck * Configs.DailyLuck.MinTimeUntilBiteMultiplier)); minTime *= (1 + (LuckLevel * Configs.PlayerLuck.MinTimeUntilBiteMultiplier)); minTime *= (1 + (FishingLevel * Configs.FishingLevel.MinTimeUntilBiteMultiplier)); minTime *= Configs.Bait == null ? 1 : Configs.Bait.MinTimeUntilBiteMultiplier; minTime *= Configs.Tackle == null ? 1 : Configs.Tackle.MinTimeUntilBiteMultiplier; foreach (LocationSettingsData LSD in Configs.AppliedLocationEffects) { minTime *= LSD.MinTimeUntilBiteMultiplier; } float maxTime = Configs.GeneralSettings.MaxTimeUntilBite; maxTime += BobberIsOnFishingPoint ? Configs.FishingPoint.MaxTimeUntilBiteAdditive : 0; maxTime += DailyLuck * Configs.DailyLuck.MaxTimeUntilBiteAdditive; maxTime += LuckLevel * Configs.PlayerLuck.MaxTimeUntilBiteAdditive; maxTime += FishingLevel * Configs.FishingLevel.MaxTimeUntilBiteAdditive; maxTime += Configs.Bait == null ? 0 : Configs.Bait.MaxTimeUntilBiteAdditive; maxTime += Configs.Tackle == null ? 0 : Configs.Tackle.MaxTimeUntilBiteAdditive; foreach (LocationSettingsData LSD in Configs.AppliedLocationEffects) { maxTime += LSD.MaxTimeUntilBiteAdditive; } maxTime *= BobberIsOnFishingPoint ? Configs.FishingPoint.MaxTimeUntilBiteMultiplier : 1; maxTime *= (1 + (DailyLuck * Configs.DailyLuck.MaxTimeUntilBiteMultiplier)); maxTime *= (1 + (LuckLevel * Configs.PlayerLuck.MaxTimeUntilBiteMultiplier)); maxTime *= (1 + (FishingLevel * Configs.FishingLevel.MaxTimeUntilBiteMultiplier)); maxTime *= Configs.Bait == null ? 1 : Configs.Bait.MaxTimeUntilBiteMultiplier; maxTime *= Configs.Tackle == null ? 1 : Configs.Tackle.MaxTimeUntilBiteMultiplier; foreach (LocationSettingsData LSD in Configs.AppliedLocationEffects) { maxTime *= LSD.MaxTimeUntilBiteMultiplier; } maxTime = Math.Max(minTime + 1, maxTime); Rod.timeUntilFishingBite = rand.Next((int)minTime, (int)maxTime); Rod.timeUntilFishingBite = Math.Max(1.0f, Rod.timeUntilFishingBite); if (Configs.GeneralSettings.VerboseLogging) { Monitor.Log(String.Format("Fishing Tuner Redux: Rod.timeUntilFishingBite set to {0}", Rod.timeUntilFishingBite), LogLevel.Info); } } if (Rod.timeUntilFishingNibbleDone != -1 && !Nibbling) { Nibbling = true; float minTime = Configs.GeneralSettings.MinNibbleTime; minTime += BobberIsOnFishingPoint ? Configs.FishingPoint.MinNibbleTimeAdditive : 0; minTime += DailyLuck * Configs.DailyLuck.MinNibbleTimeAdditive; minTime += LuckLevel * Configs.PlayerLuck.MinNibbleTimeAdditive; minTime += FishingLevel == 0 ? 0 : (FishingLevel * Configs.FishingLevel.MinNibbleTimeAdditive); minTime += Configs.Bait == null ? 0 : Configs.Bait.MinNibbleTimeAdditive; minTime += Configs.Tackle == null ? 0 : Configs.Tackle.MinNibbleTimeAdditive; foreach (LocationSettingsData LSD in Configs.AppliedLocationEffects) { minTime += LSD.MinNibbleTimeAdditive; } minTime *= BobberIsOnFishingPoint ? Configs.FishingPoint.MinNibbleTimeMultiplier : 1; minTime *= (1 + (DailyLuck * Configs.DailyLuck.MinNibbleTimeMultiplier)); minTime *= (1 + (LuckLevel * Configs.PlayerLuck.MinNibbleTimeMultiplier)); minTime *= (1 + (FishingLevel * Configs.FishingLevel.MinNibbleTimeMultiplier)); minTime *= Configs.Bait == null ? 1 : Configs.Bait.MinNibbleTimeMultiplier; minTime *= Configs.Tackle == null ? 1 : Configs.Tackle.MinNibbleTimeMultiplier; foreach (LocationSettingsData LSD in Configs.AppliedLocationEffects) { minTime *= LSD.MinNibbleTimeMultiplier; } float maxTime = Configs.GeneralSettings.MaxNibbleTime; maxTime += BobberIsOnFishingPoint ? Configs.FishingPoint.MaxTimeUntilBiteAdditive : 0; maxTime += DailyLuck * Configs.DailyLuck.MaxNibbleTimeAdditive; maxTime += LuckLevel * Configs.PlayerLuck.MaxNibbleTimeAdditive; maxTime += FishingLevel * Configs.FishingLevel.MaxNibbleTimeAdditive; maxTime += Configs.Bait == null ? 0 : Configs.Bait.MaxNibbleTimeAdditive; maxTime += Configs.Tackle == null ? 0 : Configs.Tackle.MaxNibbleTimeAdditive; foreach (LocationSettingsData LSD in Configs.AppliedLocationEffects) { maxTime += LSD.MaxNibbleTimeAdditive; } maxTime *= BobberIsOnFishingPoint ? Configs.FishingPoint.MaxTimeUntilBiteMultiplier : 1; maxTime *= (1 + (DailyLuck * Configs.DailyLuck.MaxNibbleTimeMultiplier)); maxTime *= (1 + (LuckLevel * Configs.PlayerLuck.MaxNibbleTimeMultiplier)); maxTime *= (1 + (FishingLevel * Configs.FishingLevel.MaxNibbleTimeMultiplier)); maxTime *= Configs.Bait == null ? 1 : Configs.Bait.MaxNibbleTimeMultiplier; maxTime *= Configs.Tackle == null ? 1 : Configs.Tackle.MaxNibbleTimeMultiplier; foreach (LocationSettingsData LSD in Configs.AppliedLocationEffects) { maxTime *= LSD.MaxNibbleTimeMultiplier; } maxTime = Math.Max(minTime + 1, maxTime); Rod.timeUntilFishingNibbleDone = rand.Next((int)minTime, (int)maxTime); Rod.timeUntilFishingNibbleDone = Math.Max(1.0f, Rod.timeUntilFishingNibbleDone); if (Configs.GeneralSettings.VerboseLogging) { Monitor.Log(String.Format("Fishing Tuner Redux: Rod.timeUntilFishingNibbleDone set to {0}", Rod.timeUntilFishingNibbleDone), LogLevel.Info); } } } }