当前位置: 首页>>代码示例>>C#>>正文


C# Chunk.Add32Bit方法代码示例

本文整理汇总了C#中Chunk.Add32Bit方法的典型用法代码示例。如果您正苦于以下问题:C# Chunk.Add32Bit方法的具体用法?C# Chunk.Add32Bit怎么用?C# Chunk.Add32Bit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chunk的用法示例。


在下文中一共展示了Chunk.Add32Bit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChunkMessageFile

        private void ChunkMessageFile(string fileName)
        {
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);

            messageChunks.Clear();

            int n_byte = nBitPerBlock / 8;
            int offset = 0;
            byte[] temp = new byte[n_byte];
            int length = fs.Read(temp, offset, n_byte);

            //Console.WriteLine(Encoding.ASCII.GetString(temp));
            Chunk chunk;

            while (length == n_byte)
            {
                chunk = new Chunk();

                for (int i = 0; i < n_byte; i += 4)
                {
                    chunk.Add32Bit(BytesToUInt(new byte[4] { temp[i], temp[i+1], temp[i+2], temp[i+3] }));
                }

                messageChunks.Add(chunk);

                offset += length;
                length = fs.Read(temp, 0, n_byte);
                //Console.WriteLine(Encoding.ASCII.GetString(temp));
            }
            //Console.WriteLine(Encoding.ASCII.GetString(temp) +":"+ length);

            int k_zero = n_byte - ((int)(fs.Length % n_byte)) - 64 / 8;
            if (k_zero == 0) k_zero = 448 / 8;

            //Console.WriteLine("Zero adding : "+ k_zero);

            byte[] bytes_to_append = new byte[k_zero];
            bytes_to_append[0] = 128;
            for (int i = 1; i < k_zero; i++)
            {
                bytes_to_append[i] = 0;
            }

            bytes_to_append = bytes_to_append.Concat(LongToBytes(fs.Length*8,64/8)).ToArray();

            int i_append = 0;
            if (length > 0)
            {
                for (int i = length; i < n_byte; i++)
                {
                    temp[i] = bytes_to_append[i_append++];
                }

                chunk = new Chunk();

                for (int i = 0; i < n_byte; i += 4)
                {
                    chunk.Add32Bit(BytesToUInt(new byte[4] { temp[i], temp[i + 1], temp[i + 2], temp[i + 3] }));
                }
                messageChunks.Add(chunk);
            }
            //Console.WriteLine("Length of Bit Append :" + bytes_to_append.Count());
            //Console.WriteLine("Index of Bit Append :" + i_append);
            while (i_append < bytes_to_append.Count())
            {
                chunk = new Chunk();
                for (int i = 0; i < n_byte; i += 4)
                {
                    chunk.Add32Bit(BytesToUInt(new byte[4] { bytes_to_append[i_append], bytes_to_append[i_append+1],
                    bytes_to_append[i_append+2], bytes_to_append[i_append+3] }));
                    i_append += 4;
                }
                messageChunks.Add(chunk);
            }

            fs.Close();
        }
开发者ID:andhikanugraha,项目名称:sigamal,代码行数:77,代码来源:SHA256.cs

示例2: ChunkMessage

        private void ChunkMessage(string message)
        {
            messageChunks.Clear();

            int n_byte = nBitPerBlock / 8;
            int offset = 0;
            byte[] temp = new byte[n_byte];

            int length = (message.Length-offset) > n_byte ? n_byte : message.Length-offset;
            Encoding.ASCII.GetBytes(message.Substring(offset, length)).CopyTo(temp, 0);

            Chunk chunk;

            while (length == n_byte)
            {
                chunk = new Chunk();

                for (int i = 0; i < n_byte; i += 4)
                {
                    chunk.Add32Bit(BytesToUInt(new byte[4] { temp[i], temp[i + 1], temp[i + 2], temp[i + 3] }));
                }

                messageChunks.Add(chunk);

                offset += length;
                length = (message.Length-offset) > n_byte ? n_byte : message.Length-offset;
                Encoding.ASCII.GetBytes(message.Substring(offset, length)).CopyTo(temp, 0);
                Console.WriteLine(Encoding.ASCII.GetString(temp));
            }
            //Console.WriteLine(Encoding.ASCII.GetString(temp) + ":" + length);

            int k_zero = n_byte - ((int)(message.Length % n_byte)) - 64 / 8;
            if (k_zero == 0) k_zero = 448 / 8;

            //Console.WriteLine("Zero adding : " + k_zero);

            byte[] bytes_to_append = new byte[k_zero];
            bytes_to_append[0] = 128;
            for (int i = 1; i < k_zero; i++)
            {
                bytes_to_append[i] = 0;
            }

            bytes_to_append = bytes_to_append.Concat(LongToBytes(message.Length * 8, 64 / 8)).ToArray();

            int i_append = 0;
            if (length > 0)
            {
                for (int i = length; i < n_byte; i++)
                {
                    temp[i] = bytes_to_append[i_append++];
                }

                chunk = new Chunk();

                for (int i = 0; i < n_byte; i += 4)
                {
                    chunk.Add32Bit(BytesToUInt(new byte[4] { temp[i], temp[i + 1], temp[i + 2], temp[i + 3] }));
                }
                messageChunks.Add(chunk);
            }
            //Console.WriteLine("Length of Bit Append :" + bytes_to_append.Count());
            //Console.WriteLine("Index of Bit Append :" + i_append);
            while (i_append < bytes_to_append.Count())
            {
                chunk = new Chunk();
                for (int i = 0; i < n_byte; i += 4)
                {
                    chunk.Add32Bit(BytesToUInt(new byte[4] { bytes_to_append[i_append], bytes_to_append[i_append+1],
                    bytes_to_append[i_append+2], bytes_to_append[i_append+3] }));
                    i_append += 4;
                }
                messageChunks.Add(chunk);
            }
        }
开发者ID:andhikanugraha,项目名称:sigamal,代码行数:75,代码来源:SHA256.cs


注:本文中的Chunk.Add32Bit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。