Beispiel #1
0
        /**
         * Masks a file with an image given a file and image.
         */
        public static string[] Mask(string file, string image)
        {
            //Create a new Bitmap objects and map pixels/bits.
            var img = new Bitmap(image);

            Color[] pixels = GetPixels(img);
            var pixelBits = new int[pixels.Length];

            for (int n = 0, length = pixels.Length; n < length; n++)
                pixelBits[n] = Util.ColorToBits(pixels[n]);

            //Read all bits from the file to mask.
            byte[] bytes = File.ReadAllBytes(file);
            var bits = new BitArray(bytes);

            //Merge bits.
            var tour = new Tour(img.Width, img.Height);
            pixelBits = Merge(bits, tour, pixelBits);

            //Generate pixel colors based on each the merged bits.
            for (int n = 0, length = pixelBits.Length; n < length; n++)
                pixels[n] = Util.BitsToColor(pixelBits[n]);

            Bitmap maskedImage = CreateImage(img.Width, img.Height, pixels);

            //Save the new image.
            string dir = Path.GetDirectoryName(image);
            string name = Path.GetFileNameWithoutExtension(image);
            string extension = Path.GetExtension(image);

            Benchmark mark = new Benchmark("Time to Write Masked File", true);

            maskedImage.Save(dir + "\\" + name + " - Masked" + extension);

            mark.Time();

            //Generate AES keys and return.
            mark = new Benchmark("Time to Generate Encryption Keys", true);

            string[] hash = Crypt.Encrypt(Path.GetFileName(file) + ":" + bits.Length + ":" + tour.Export());

            mark.Time();

            return hash;
        }