Esempio n. 1
0
        /// <summary>
        /// Exports the text from the selected image file by starting from top left corner.
        /// </summary>
        public void Export()
        {
            _form.ExportTextBoxText = string.Empty;
            _form.Sw = new Stopwatch();
            _form.Sw.Start();
            _form.ExportProgressBarValue = 0;

            var importedTextLength = CheckBeforeExport();

            if (importedTextLength != 0)
            {
                _form.Bmp = new Bitmap(_form.ExportPictureBoxImage);
                int totalBytes     = importedTextLength * 7;
                int totalPixels    = totalBytes / 3;
                int totalBytesMod3 = totalBytes % 3;
                if (totalBytesMod3 != 0)
                {
                    totalPixels++;
                }
                _form.ExportProgressBarMaximum = importedTextLength + totalPixels;

                var    bytesToExport     = _helper.GetOnlyNecessaryBytesFromImage(totalPixels, totalBytesMod3, _form.ExpProgressBar);
                int    pointer           = 6; //++++
                string bytesToExportLast = string.Empty;
                string importedText      = null;

                for (int l = 0; l < totalBytes; l++) // Getting the last bit of each bytes and stores to 'bytesToExportast'
                {
                    bytesToExportLast += bytesToExport.Substring(pointer, 2);
                    pointer           += 8;
                }
                int decrease = 0, k = 0, temp = 0;
                importedText = string.Empty;

                for (int j = 0; j < bytesToExportLast.Length / 14; j++)
                {
                    for (int i = k; i < k + 14; i++)
                    {
                        temp += Convert.ToInt32(bytesToExportLast.Substring(i, 1)) * (int)Math.Pow(2, (13 - decrease));
                        decrease++;
                    }

                    if (temp >= 1000)
                    {
                        importedText += Encoding.Unicode.GetString(BitConverter.GetBytes(temp + 43032)).TrimEnd((Char)0);
                    }
                    else if (temp < 13)
                    {
                        importedText += _helper.NumberToTurkishChar(temp);
                    }
                    else
                    {
                        importedText += Encoding.Unicode.GetString(BitConverter.GetBytes(temp)).TrimEnd((Char)0);
                    }

                    _form.ExpProgressBar.Increment(1);
                    k += 14; temp = decrease = 0;
                }

                //_form.ExportTextBoxText = importedText;
                _form.ExportTextBoxText = EllipticCurvesEncryption.DecryptString(importedText);
                SetInfoLabels();
            }
            else
            {
                MessageBox.Show("This is not a stego file!", CommonConstants.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Imports the text into the selected image file by starting from top left corner.
        /// </summary>
        public void Import()
        {
            //cryptText = EllipticCurve.CryptInfo(_form.ImportTextBoxText);
            cryptText = EllipticCurvesEncryption.EncryptString(_form.ImportTextBoxText);
            _form.Sw  = new Stopwatch();
            _form.Sw.Start();
            _form.ImportProgressBarValue = 0;

            if (CheckBeforeImport())
            {
                string bitsToImport   = string.Empty;
                var    charsToImport  = cryptText.ToCharArray();
                var    totalBytes     = charsToImport.Length * 7;
                var    totalPixels    = totalBytes / 3; // Total number of pixels to be used..
                var    totalBytesMod3 = totalBytes % 3;
                if (totalBytesMod3 != 0)
                {
                    totalPixels++;
                }
                _form.ImportProgressBarMaximum = totalPixels + totalBytes;

                var charToBits = string.Empty;

                foreach (var chr in charsToImport)// bitsToImport holds the bit form of the character that will be imported.
                {
                    if (chr >= Korea_First_Index)
                    {
                        charToBits = Convert.ToString(chr - Korea_First_Index + 1000, 2);
                        //(Chr - Korean_First_Index is to reduce 16 bits to 14 bits) (The reason that add 1000 to text is to protect overlapping with turkish).
                    }
                    else
                    {
                        charToBits = Convert.ToString(chr, 2); //if chr is not Korean, change to binary
                    }

                    if (charToBits.Length > 7 && charToBits.Length < 9) // if it's binary is between 7 and 9
                    {
                        bitsToImport += _helper.TurkishCharTo7Bit(chr); // set to 14 bits in Turkish letter
                    }
                    else
                    {
                        bitsToImport += charToBits.PadLeft(14, '0'); // If less than 14 bits, padding the leading 0
                    }
                }

                var imageBits = _helper.GetOnlyNecessaryBytesFromImage(totalPixels, totalBytesMod3, _form.ImpProgressBar);
                int sevenBitPointer = 0, oneBitPointer = 0;
                var imageBitsLast = string.Empty;

                while (bitsToImport.Length > oneBitPointer) //bitsToImport is importing into imagebits. the result is stored in imageBitLast.
                {
                    imageBitsLast   += imageBits.Substring(sevenBitPointer, 6) + (bitsToImport.Substring(oneBitPointer, 2));
                    oneBitPointer    = oneBitPointer + 2;
                    sevenBitPointer += 8;
                    _form.ImpProgressBar.Increment(1);
                }

                ImportTextLength();
                imageBitsLast += imageBits.Substring(sevenBitPointer);
                _form.ImportPictureBoxImage = _form.Bmp = _helper.ByteArrayToBitmap(_helper.StringToByteArray(imageBitsLast));
                SetInfoLabels();
            }
        }