/// <summary> /// Decrypts a text from a BitmapImage /// </summary> /// <param name="picture">The picture in which a text will be searched for</param> /// <param name="usage">How many bits will be used in each channel</param> /// <param name="seed">The seed used in the generator for the order of pixels</param> /// <returns>Text found in the picture</returns> public static string Decrypt(BitmapImage picture, ChannelUsage usage, int seed) { using (var decrypter = new Decrypter(new Picture(picture.ToByteArray(), seed, picture.PixelHeight, picture.PixelWidth))) { var text = decrypter.ReadText(usage); return((text == "") ? "No text found." : text); } }
public static string Decrypt(Bitmap encryptedPicture, ChannelUsage usage, int seed) { using (encryptedPicture) using (var decrypter = new Decrypter(new Picture(encryptedPicture, seed))) { var text = decrypter.ReadText(usage); return((text == "") ? "No text found." : text); } }
public void TestEncrypt() { const string text = "Sample text to hide"; var image = ColoredBitmap.CreateBitmap(100, 100); var usage = new ChannelUsage(2); var picture = Interface.Encrypt(image, usage, 0, text); var decrypter = new Decrypter(new Picture(picture)); var resText = decrypter.ReadText(usage); Assert.AreEqual(text, resText); }
public void TestNoAlpha() { const string text = "Sample Text written with 2 bits per channel, but not using the alpha channel"; var usage = new ChannelUsage(2, 2, 2); var encrypter = new Encrypter(new Picture(new Bitmap(20, 20))); encrypter.InsertText(text, usage); var picture = encrypter.GetPictureData(); var decrypter = new Decrypter(picture); var res = decrypter.ReadText(usage); Assert.AreEqual(text, res); }
public void TestChnUsage() { const string text = "Sample Text written with 3 bits per channel which gives the possibility to store more text"; var usage = new ChannelUsage(3); var encrypter = new Encrypter(new Picture(new Bitmap(20, 20))); encrypter.InsertText(text, usage); var picture = encrypter.GetPictureData(); var decrypter = new Decrypter(picture); var res = decrypter.ReadText(usage); Assert.AreEqual(text, res); }
public void TestLong() { const string text = "Pretty long text just to test if everything is working properly!"; var usage = new ChannelUsage(2); var encrypter = new Encrypter(new Picture(ColoredBitmap.CreateBitmap(20, 20, Color.Aqua), 0)); encrypter.InsertText(text, usage); var picture = encrypter.GetPictureData(); var decrypter = new Decrypter(picture); var res = decrypter.ReadText(usage); Assert.AreEqual(text, res); }
public void TestShort() { const string text = "Sample Text to hide"; var usage = new ChannelUsage(2); var encrypter = new Encrypter(new Picture(ColoredBitmap.CreateBitmap(10, 10, Color.Aqua), 0)); encrypter.InsertText(text, usage); var picture = encrypter.GetPictureData(); var decrypter = new Decrypter(picture); var res = decrypter.ReadText(usage); Assert.AreEqual(text, res); }
public void TestDifferentChnUsage() { const string text = "Sample Text written with different bits used per channel, but not using the alpha channel"; var usage = new ChannelUsage(2, 3, 0, 1); var encrypter = new Encrypter(new Picture(100, 100)); encrypter.InsertText(text, usage); var picture = encrypter.GetPictureData(); var decrypter = new Decrypter(picture); var res = decrypter.ReadText(usage); Assert.AreEqual(text, res); }
public void TestWrongSeed() { const int seed = 26; const string text = "This won't work because we use another seed for decrypting our image"; var usage = new ChannelUsage(2); var encrypter = new Encrypter(new Picture(new Bitmap(20, 20), seed)); encrypter.InsertText(text, usage); var picture = encrypter.GetPictureData(); var decrypter = new Decrypter(new Picture(picture.GetImage(), 0)); var res = decrypter.ReadText(usage); Assert.AreNotEqual(text, res); }
public void TestSeed() { const int seed = 23; const string text = "Sample Text to hide"; var usage = new ChannelUsage(2); var encrypter = new Encrypter(new Picture(new Bitmap(20, 20), seed)); encrypter.InsertText(text, usage); var picture = encrypter.GetPictureData(); var decrypter = new Decrypter(picture); var res = decrypter.ReadText(usage); Assert.AreEqual(text, res); }
public void TestWrongChnUsage() { const string text = "Sample Text written with 2 bits per channel, but not using the alpha channel while encrypting but using it when decrypting"; var usage = new ChannelUsage(2, 3, 3, 2); var encrypter = new Encrypter(new Picture(100, 100)); encrypter.InsertText(text, usage); var picture = encrypter.GetPictureData(); var decrypter = new Decrypter(picture); usage = new ChannelUsage(3, 2, 2, 3); var res = decrypter.ReadText(usage); Assert.AreNotEqual(text, res); }
public void TestSingleCharTagless() { const string text = "s"; var image = ColoredBitmap.CreateBitmap(1, 1); var usage = new ChannelUsage(2); var encrypter = new Encrypter(new Picture(image)); encrypter.InsertText(text, usage, false); var resImage = encrypter.GetPictureData().GetImage(); encrypter.Dispose(); var decrypter = new Decrypter(new Picture(resImage)); var resText = decrypter.ReadText(usage, false); Assert.AreEqual(text, resText); }