Esempio n. 1
0
        public static string FileReadToBinary(string filename)
        {
            FileStream fs = new FileStream("C:\\" + filename, FileMode.Open);

            Console.WriteLine("File size : " + fs.Length);
            // Read from file 100bytes per 1 time and transform to binary data.
            int           fileLength = (int)fs.Length;
            StringBuilder text       = new StringBuilder((int)fs.Length * 8);

            byte[] bytes      = new byte[100];
            int    startindex = 0;
            int    IsEnd      = -1;

            while (fs.Read(bytes, startindex, bytes.Length) != 0)
            {
                if (IsEnd > 0)
                {
                }
                foreach (byte b in bytes)
                {
                    if (text.Length == fileLength * 8)
                    {
                        break;
                    }
                    text.Append(ProcessDES.FromDecimalToBinary(b));
                }
            }
            fs.Close();
            return(text.ToString());
        }
Esempio n. 2
0
        public string DoPermutation(string text, int[,] order)
        {
            // text chứa chuỗi 6 bit
            // order là mảng 4 dòng 16 cột
            string PermutatedText = "";
            // Bit đầu ghép bit cuối làm số dòng (0-->3)
            int rowIndex = Convert.ToInt32(text[0].ToString() + text[text.Length - 1].ToString(), 2);
            // 4 bit giữa làm số cột (0-->15)
            int colIndex = Convert.ToInt32(text.Substring(1, 4), 2);

            // Từ 6 bit chuyển thành 4 bit
            PermutatedText = ProcessDES.FromDecimalToBinary(order[rowIndex, colIndex]);
            // Lấy phần tử ở mảng order, với giá trị từ 0 đến 15, chuyển sang chuỗi nhị phân
            return(PermutatedText);
        }