예제 #1
0
 public void Check_size_image(ERRORS eror)
 {
     if (checking.biSizeImage.znach + 54 != checking.bfSize.znach + 2)
     {
         eror.index_for_errors = 5;
     }
 }
예제 #2
0
 public void Reverse2(ERRORS eror)
 {
     if (checking.bfReserved2.value != 0)
     {
         eror.index_for_errors = 6;
     }
 }
예제 #3
0
 public void Check_the_Pixels(ERRORS eror)
 {
     if (((checking.biHeight.znach * checking.biWidth.znach * checking.biBitCount.value) / 8) != checking.biSizeImage.znach)
     {
         eror.index_for_errors = 4;
     }
 }
예제 #4
0
 public void Check_the_Planes(ERRORS eror)
 {
     if (checking.biPlanes.value >= 1)
     {
         eror.index_for_errors = 3;
     }
 }
예제 #5
0
 public void Check_the_compression(ERRORS eror)
 {
     if (checking.biCompression.znach != 0)
     {
         eror.index_for_errors = 2;
     }
 }
예제 #6
0
 public void Check_the_title(ERRORS eror)
 {
     if (checking.bfType.value != 0X4D42)
     {
         eror.index_for_errors = 1;
     }
 }
예제 #7
0
 public void Check_the_equality_between_size_Image_and_BYTES_FOR_THE_LSB(uint size, ERRORS eror)
 {
     if (checking.biSizeImage.znach - 36 != size - 52)
     {
         eror.index_for_errors = 7;
     }
 }
예제 #8
0
        static void Main(string[] args)
        {
            const string text = "Cat_dog_rog_fog_female_marker_kreker";

            Stream input  = Console.OpenStandardInput();
            Stream output = Console.OpenStandardOutput();
            Stream stderr = Console.OpenStandardError();

            uint size = 0;//for the LSB

            Fields PEMP = new Fields();

            input.Read(WORD, 0, 2);
            output.Write(WORD, 0, 2);
            WORD.Reverse();
            PEMP.bfType.value = Transform_to_two_bytes();

            input.Read(DWORD, 0, 4);
            output.Write(DWORD, 0, 4);
            DWORD.Reverse();
            PEMP.bfSize.znach = Transform_to_four_bytes();

            size = PEMP.bfSize.znach - 2;

            input.Read(WORD, 0, 2);
            output.Write(WORD, 0, 2);
            WORD.Reverse();
            PEMP.bfReserved1.value = Transform_to_two_bytes();

            input.Read(WORD, 0, 2);
            output.Write(WORD, 0, 2);
            WORD.Reverse();
            PEMP.bfReserved2.value = Transform_to_two_bytes();

            input.Read(DWORD, 0, 4);
            output.Write(DWORD, 0, 4);
            DWORD.Reverse();
            PEMP.bfOffBits.znach = Transform_to_four_bytes();

            input.Read(DWORD, 0, 4);
            output.Write(DWORD, 0, 4);
            DWORD.Reverse();
            PEMP.biSize.znach = Transform_to_four_bytes();

            input.Read(DWORD, 0, 4);
            output.Write(DWORD, 0, 4);
            DWORD.Reverse();
            PEMP.biWidth.znach = Transform_to_four_bytes();

            input.Read(DWORD, 0, 4);
            output.Write(DWORD, 0, 4);
            DWORD.Reverse();
            PEMP.biHeight.znach = Transform_to_four_bytes();

            input.Read(WORD, 0, 2);
            output.Write(WORD, 0, 2);
            WORD.Reverse();
            PEMP.biPlanes.value = Transform_to_two_bytes();

            input.Read(WORD, 0, 2);
            output.Write(WORD, 0, 2);
            WORD.Reverse();
            PEMP.biBitCount.value = Transform_to_two_bytes();

            input.Read(DWORD, 0, 4);
            output.Write(DWORD, 0, 4);
            DWORD.Reverse();
            PEMP.biCompression.znach = Transform_to_four_bytes();

            input.Read(DWORD, 0, 4);
            output.Write(DWORD, 0, 4);
            DWORD.Reverse();
            PEMP.biSizeImage.znach = Transform_to_four_bytes();

            input.Read(DWORD, 0, 4);
            output.Write(DWORD, 0, 4);
            DWORD.Reverse();
            PEMP.biXPelsPerMeter.znach = Transform_to_four_bytes();

            input.Read(DWORD, 0, 4);
            output.Write(DWORD, 0, 4);
            DWORD.Reverse();
            PEMP.biYPelsPerMeter.znach = Transform_to_four_bytes();

            input.Read(DWORD, 0, 4);
            output.Write(DWORD, 0, 4);
            DWORD.Reverse();
            PEMP.biClrUsed.znach = Transform_to_four_bytes();

            input.Read(DWORD, 0, 4);
            output.Write(DWORD, 0, 4);
            DWORD.Reverse();
            PEMP.biClrImportant.znach = Transform_to_four_bytes();

            byte[] BYTES_FOR_LSB = new byte[size - 52];

            input.Read(BYTES_FOR_LSB, 0, BYTES_FOR_LSB.Length);

            ERRORS erer     = new ERRORS();
            CHECK  checking = new CHECK();

            checking.Check_the_title(erer);
            checking.Reverse1(erer);
            checking.Reverse2(erer);
            checking.Check_size_image(erer);
            checking.Check_the_compression(erer);
            checking.Check_the_equality_between_size_Image_and_BYTES_FOR_THE_LSB(size, erer);
            checking.Check_the_Pixels(erer);
            checking.Check_the_Planes(erer);

            byte[] for_problems = new byte[4];

            erer.The_Reasons();
            stderr.WriteByte((byte)(erer.index_for_errors));
            string strings = "Not problems";

            strings = erer.comments;
            if (strings != null)
            {
                stderr.Write(Encoding.ASCII.GetBytes(strings), 0, strings.Length);
                Environment.Exit(1);
            }



            byte[] leght = new byte[4];
            string str_length;

            byte[] bit_str_length;
            byte[] bit_lok;
            bit_lok    = Utilits.Bytes_Fulled_Bits(text);
            str_length = BYTES_FOR_LSB.Length.ToString();

            while (str_length.Length < 8)
            {
                str_length += 's';
            }

            bit_str_length = Utilits.Bytes_Fulled_Bits(str_length);

            if (args[0] == "-Enc")
            {
                for (int i = 0; i < bit_lok.Length + 32; i++)
                {
                    if (i >= 32)
                    {
                        BYTES_FOR_LSB[i] = Utilits.Bit_To_Byte(BYTES_FOR_LSB[i], bit_lok[i - 32]);
                    }
                    else
                    {
                        BYTES_FOR_LSB[i] = Utilits.Bit_To_Byte(BYTES_FOR_LSB[i], bit_str_length[i]);
                    }
                }

                output.Write(BYTES_FOR_LSB, 0, BYTES_FOR_LSB.Length);
            }
            if (args[0] == "-Dec")
            {
                string str_res = " ";
                for (int i = 0; i < BYTES_FOR_LSB.Length; i++)
                {
                    if (i >= 2)
                    {
                        byte[] bit_res = new byte[bit_lok.Length];
                        Array.Copy(BYTES_FOR_LSB, 32, bit_res, 0, bit_lok.Length);
                        str_res = Utilits.FourBitToStr(bit_res);
                        break;
                    }
                    else
                    {
                        byte[] bit_size = new byte[32];
                        Array.Copy(bit_str_length, bit_size, 32);
                        foreach (var cur in bit_size)
                        {
                            Console.Write(cur);
                        }
                        string str_size = Utilits.FourBitToStr(bit_size);
                        string size_    = str_size.Substring(0, str_size.IndexOf('s'));
                    }
                }
                stderr.Write(Encoding.ASCII.GetBytes(str_res), 0, str_res.Length);
            }
        }