public static void EncryptInImage(string path, string input) { var img = new Bitmap(path); var pixels = DEShelper.GetPixels(img).ToArray(); var binInput = DEShelper.TextToBinary(input).ToArray(); for (int i = 0; i < binInput.Count(); i++) { img.SetPixel(i % img.Width, i / img.Width, Color.FromArgb(pixels[i].A, ChangeByte(pixels[i].R, binInput[i]), pixels[i].G, pixels[i].B)); } img.Save($"encrypted{path}"); }
public static string DecryptTextFromImage(string path, int length) { var img = new Bitmap(path); var pixels = DEShelper.GetPixels(img).ToArray(); var binOutput = new List <int>(); for (int i = 0; i < 8 * length; i++) { binOutput.Add(GetLastBit(pixels[i].R)); } return(DEShelper.BinaryToText(binOutput.ListToString())); }
public void DecryptImage(string imagePath, IEnumerable <int> key, string outName) { Console.WriteLine("Decrypting"); var colors = DEShelper.GetPixels(imagePath).ToArray(); var encryptedColors = new List <IEnumerable <int> >(); var len = colors.Count(); for (int i = 0; i < len; i += 2) { var bin1 = Convert.ToString(Convert.ToInt64(colors[i].Name, 16), 2).PadLeft(32, '0').ToIntList(); var bin2 = Convert.ToString(Convert.ToInt64(colors[i + 1].Name, 16), 2).PadLeft(32, '0').ToIntList(); encryptedColors.Add(Decrypt(bin1.Concat(bin2), key).ToList()); } Console.WriteLine("Decrypted\nSaving..."); DEShelper.SaveImage64x64(encryptedColors, outName); Console.WriteLine($"Saved {outName}"); }