コード例 #1
0
ファイル: HideNSeek.cs プロジェクト: kcwong395/HideNSeek
        // application is opened with file(s) passing in
        public HideNSeek(string[] imgs)
        {
            InitializeComponent();

            // only the first image will be processed
            // pass the selected file to check whether it is an image
            if (ImgProcessing.isImg(imgs[0]))
            {
                Reinitialize("", "File Selected: " + imgs[0], imgs[0], new Bitmap(imgs[0]));
            }
            else
            {
                MessageBox.Show("Error: This image is not supported", "Alert");
            }
        }
コード例 #2
0
        public static string ExtractMsg(string rawInput, Bitmap imgMap)
        {
            // pre-processing the hidden message
            string key = KeyExtract(ref rawInput);

            int[] indexList = IndexExtract(ref rawInput);

            byte[] textInByte = ImgProcessing.ExtractByte(imgMap, indexList);

            if (!string.IsNullOrEmpty(key))
            {
                // Decrypt the bytes to a string.
                return(CryptoHandler.DecryptStringFromBytes_Aes(textInByte, key, CryptoHandler.IV));
            }
            else
            {
                return(Encoding.UTF8.GetString(textInByte));
            }
        }
コード例 #3
0
        // return 0 if space is not enough
        public static int InsertMsg(string rawInput, Bitmap imgMap)
        {
            // detect if a key input exist in the raw data
            string key = KeyExtract(ref rawInput);

            // detect if the user input an index tag
            int[] indexList = IndexExtract(ref rawInput);

            byte[] textInByte;

            // if the user inputs a key, encrypted the text input
            if (!string.IsNullOrEmpty(key))
            {
                // Encrypt the string to an array of bytes.
                byte[] plainByte = CryptoHandler.EncryptStringToBytes_Aes(rawInput, key, CryptoHandler.IV);
                byte[] str       = Encoding.UTF8.GetBytes("<STR>");
                byte[] end       = Encoding.UTF8.GetBytes("<END>");
                textInByte = new byte[str.Length + plainByte.Length + end.Length];
                Buffer.BlockCopy(str, 0, textInByte, 0, str.Length);
                Buffer.BlockCopy(plainByte, 0, textInByte, str.Length, plainByte.Length);
                Buffer.BlockCopy(end, 0, textInByte, end.Length + plainByte.Length, end.Length);
            }
            else
            {
                // prolong the plaintext with the header
                string plaintext = "<STR>" + rawInput + "<END>";
                textInByte = Encoding.UTF8.GetBytes(plaintext);
            }

            long availableWidth  = (imgMap.Width - indexList[1]) / indexList[3];
            long availableHeight = (imgMap.Height - indexList[0]) / indexList[2];
            long availableSpace  = (availableWidth + availableHeight) * (indexList[4] + indexList[5] + indexList[6]);

            if (availableSpace >= textInByte.Length * 8 && availableHeight > 0 && availableWidth > 0)
            {
                ImgProcessing.InsertByte(textInByte, imgMap, indexList);
                return(1);
            }
            else
            {
                return(0);
            }
        }
コード例 #4
0
ファイル: HideNSeek.cs プロジェクト: kcwong395/HideNSeek
        private void Open_Click(object sender, EventArgs e)
        {
            // open the file browser
            OpenFileDialog dlg = new OpenFileDialog
            {
                Title            = "Select an image",
                InitialDirectory = "C:/"
            };

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                if (ImgProcessing.isImg(dlg.FileName))
                {
                    Reinitialize("", "File Selected: " + dlg.FileName, dlg.FileName, new Bitmap(dlg.FileName));
                }
                else
                {
                    MessageBox.Show("Error: This image is not supported", "Alert");
                }
            }
        }