本文整理汇总了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();
}
示例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);
}
}