Exemple #1
0
        private void loadImage_Click(object sender, EventArgs e)
        {
            loadDialog.FileName = "*.*";
            DialogResult res = loadDialog.ShowDialog();

            if (res == System.Windows.Forms.DialogResult.OK)
            {
                if (image != null)
                {
                    image.Dispose();
                }
                string ext = Path.GetExtension(loadDialog.FileName);
                if (ext == ".png" || ext == ".bmp" || ext == ".jpg")
                {
                    try
                    {
                        image          = Image.FromFile(loadDialog.FileName);
                        imageBox.Image = image;
                        OutputConsole.Write(string.Format("Image loaded \nTotal pixels = {0}", image.Width * image.Height));
                        OutputConsole.Write(string.Format("Maximum file size for this image = {0} - (file size digits + file name character count) bytes", FileSizeFormatProvider.GetFileSize((image.Width * image.Height) - 2)));
                        currentMode        = Mode.Image;
                        audio              = null;
                        audioLabel.Visible = false;
                    }
                    catch
                    {
                        image          = null;
                        imageBox.Image = null;
                    }
                }
            }
        }
        private static void EncodeFileWithColor2(ref Bitmap img, byte[] file, string filename)
        {
            Bitmap backup    = img.Clone() as Bitmap;
            int    maxLinear = img.Width * img.Height;

            OutputConsole.Write(string.Format("File size: {0}", FileSizeFormatProvider.GetFileSize(file.Length)));
            SeedRNG generator = new SeedRNG((maxLinear + img.Width).GetHashCode(), maxLinear, true);

            OutputConsole.Write("Seed generated");
            int        extraBytes = 2 + filename.Length + file.Length.ToString().Length;
            HiddenFile f          = new HiddenFile(file, filename);

            f.cipherFile((maxLinear + img.Width).GetHashCode());
            OutputConsole.Write("Ciphering file...");
            if (file.Length < maxLinear - extraBytes)
            {
                string fileLength = file.Length.ToString();
                OutputConsole.Write("Processing image...");
                OutputConsole.Write("Writing metadata...");
                for (int i = 0; i < fileLength.Length; i++)
                {
                    Point point  = LinearIndexToPoint(generator.NextN, img.Width, img.Height);
                    Color pixel  = img.GetPixel(point.X, point.Y);
                    char  letter = fileLength[i];
                    int   value  = Convert.ToInt32(letter);
                    img.SetPixel(point.X, point.Y, EncodePixel(pixel, value));
                }
                //Insert # to separate file length from filename
                Point point1 = LinearIndexToPoint(generator.NextN, img.Width, img.Height);
                Color pixel1 = img.GetPixel(point1.X, point1.Y);
                int   value1 = Convert.ToInt32('#');
                img.SetPixel(point1.X, point1.Y, EncodePixel(pixel1, value1));

                //Insert filename and finish with null char
                for (int i = 0; i < filename.Length; i++)
                {
                    Point point  = LinearIndexToPoint(generator.NextN, img.Width, img.Height);
                    Color pixel  = img.GetPixel(point.X, point.Y);
                    char  letter = filename[i];
                    int   value  = Convert.ToInt32(letter);
                    img.SetPixel(point.X, point.Y, EncodePixel(pixel, value));
                }
                point1 = LinearIndexToPoint(generator.NextN, img.Width, img.Height);
                pixel1 = img.GetPixel(point1.X, point1.Y);
                value1 = 0;
                img.SetPixel(point1.X, point1.Y, EncodePixel(pixel1, value1));
                OutputConsole.Write("Writing file data...");
                //Write file
                for (int i = 0; i < file.Length; i++)
                {
                    Point point = LinearIndexToPoint(generator.NextN, img.Width, img.Height);
                    Color pixel = img.GetPixel(point.X, point.Y);
                    int   value = f.file[i];
                    img.SetPixel(point.X, point.Y, EncodePixel(pixel, value));
                }
                OutputConsole.Write("Finished embedding file");
            }
            else
            {
                OutputConsole.Write("File size is greater than total pixels in image with extra data, resize or use another image to encrypt this file");
                img = null;
            }
        }
Exemple #3
0
        private void loadWavFile_Click(object sender, EventArgs e)
        {
            DialogResult res = loadWav.ShowDialog();

            if (res == System.Windows.Forms.DialogResult.OK)
            {
                audio = File.ReadAllBytes(loadWav.FileName);
                WavAudio wav = new WavAudio(audio);
                if (wav.data != null)
                {
                    OutputConsole.Write(string.Format("Audio loaded \nSamples found: {0}", wav.totalSamples));
                    OutputConsole.Write(string.Format("Maximum file size for this file = {0} - (file size digits + file name character count) bytes", FileSizeFormatProvider.GetFileSize(wav.bytesAvailable)));
                    currentMode = Mode.Audio;
                    if (image != null)
                    {
                        image.Dispose();
                    }
                    image              = null;
                    imageBox.Image     = null;
                    audioLabel.Text    = string.Format("Using Wav File: {0}", loadWav.SafeFileName);
                    audioLabel.Visible = true;
                }
                else
                {
                    audio = null;
                }
            }
        }