Exemple #1
0
 private void btnDecode_Click(object sender, EventArgs e)
 {
     if (txtPath.Text != "")
     {
         FileStream inStream = new FileStream(decPath, FileMode.Open, FileAccess.Read);
         int        offset   = 54;
         inStream.Seek(offset, 0);
         byte[] byteLength = new byte[4];
         byteLength = LSB.Decode(inStream, 4);
         int length = BitConverter.ToInt32(byteLength, 0);
         inStream.Seek(offset + 4 * 8, 0);
         byte[] buffer = new byte[length];
         while (true)
         {
             try
             {
                 buffer = LSB.Decode(inStream, length);
             }
             catch
             {
                 MessageBox.Show("Ảnh này không chứa thông tin!", "Thông báo");
                 break;
             }
             byte[] hidenMessage = new byte[4 + buffer.Length];
             hidenMessage = ByteArray(byteLength, buffer);
             byte[] byteMessage = new byte[length];
             for (int i = 0; i < length; i++)
             {
                 byteMessage[i] = hidenMessage[i + 4];
             }
             UnicodeEncoding unicode = new UnicodeEncoding();
             string          result  = unicode.GetString(byteMessage);
             txtResult.Text = result;
             MessageBox.Show("Giải mã thành công!", "Thông báo");
             break;
         }
         inStream.Close();
     }
     else
     {
         MessageBox.Show("Vui lòng chọn ảnh để giải mã!", "Thông báo");
     }
 }
Exemple #2
0
        public void CreateFile(string stPath, string ndPath, string message)
        {
            FileStream inStream = new FileStream(stPath, FileMode.Open, FileAccess.Read);
            int        offset   = 54;

            inStream.Seek(0, 0);
            byte[] header = new byte[offset];
            inStream.Read(header, 0, offset);
            FileStream outStream = new FileStream(ndPath, FileMode.Create, FileAccess.Write);

            outStream.Write(header, 0, offset);
            UnicodeEncoding unicode = new UnicodeEncoding();

            byte[] newMessageByte = AddMessage(unicode.GetBytes(message));
            inStream.Seek(offset, 0);
            LSB.Encode(inStream, newMessageByte, outStream);
            inStream.Close();
            outStream.Close();
        }