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


C# Byte.Reverse方法代码示例

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


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

示例1: FromByteArrayReversed

 public static String FromByteArrayReversed(Byte[] b)
 {
     StringBuilder sb = new StringBuilder(b.Length * 2);
     foreach (Byte _b in b.Reverse())
     {
         sb.Append(_b.ToString("x2"));
     }
     return sb.ToString();
 }
开发者ID:ystallonne,项目名称:Bitcoin-Tool,代码行数:9,代码来源:HexString.cs

示例2: Restore

 public void Restore(Byte[] distortedText, out Byte[] plainText)
 {
     int length = distortedText.Length;
     int ceiling = length - 1;
     UInt32[] rChaoticSequence = m_GenerateDistortionSequence(length).Reverse().ToArray();
     Byte[] rDistortedText = distortedText.Reverse().ToArray();
     for(int i = 0; i < length; ++i)
     {
         Utils.Swap(ref rDistortedText[i], ref rDistortedText[ceiling - rChaoticSequence[i] % length]);
     }
     plainText = rDistortedText.Reverse().ToArray();
 }
开发者ID:ZhangQichen,项目名称:ChaoticEncryption,代码行数:12,代码来源:PositionDistortion.cs

示例3: FromByteArray

 public static String FromByteArray(Byte[] b)
 {
     StringBuilder sb = new StringBuilder();
     BigInteger bi = new BigInteger(b.Reverse().Concat(new Byte[] {0x00}).ToArray()); // concat adds sign byte
     // Calc base58 representation
     while (bi > 0)
     {
         int mod = (int)(bi % 58);
         bi /= 58;
         sb.Insert(0, base58chars[mod]);
     }
     // Add 1s for leading 0x00 bytes
     for (int i = 0; i < b.Length && b[i] == 0x00; i++)
         sb.Insert(0, '1');
     return sb.ToString();
 }
开发者ID:LawrenceBotley,项目名称:LBitcoin,代码行数:16,代码来源:Base58String.cs

示例4: Parse

        private void Parse(Templates templates)
        {
            this._flowset = new List<FlowSet>();

            Int32 length = _bytes.Length - 20;

            Byte[] header = new Byte[20];
            Byte[] flowset = new Byte[length];

            Array.Copy(_bytes, 0, header, 0, 20);
            Array.Copy(_bytes, 20, flowset, 0, length);

            this._header = new Header(header);
            byte[] reverse = flowset.Reverse().ToArray();

            int templengh = 0;

            while ((templengh + 2) < flowset.Length)
            {
                UInt16 lengths = BitConverter.ToUInt16(reverse, flowset.Length - sizeof(Int16) - (templengh+2));
                Byte[] bflowsets = new Byte[lengths];
                Array.Copy(flowset, templengh, bflowsets, 0, lengths);

                FlowSet flowsets = new FlowSet(bflowsets, templates);
                this._flowset.Add(flowsets);

                templengh += lengths;
            }
        }
开发者ID:l3xis,项目名称:NetFlow,代码行数:29,代码来源:Packet.cs

示例5: GetBinaryString

        public static string GetBinaryString(Byte[] data)
        {
            string output = "";
            foreach (byte lByte in data.Reverse())
            {
                char[] b = new char[8];
                int pos = 7;
                int i = 0;

                while (i < 8)
                {
                    if ((lByte & (1 << i)) != 0)
                    {
                        b[pos] = '1';
                    }
                    else
                    {
                        b[pos] = '0';
                    }
                    pos--;
                    i++;
                }

                output += new string(b);
            }
            return output;
        }
开发者ID:offlinehacker,项目名称:Bastet-GUI,代码行数:27,代码来源:BinarySerializer.cs

示例6: Encrypt

        /// <summary>
        ///     DES加密
        /// </summary>
        /// <param name="plain">8Byte字节数组明文</param>
        /// <param name="key">8Byte字节数组密文</param>
        /// <returns></returns>
        public static byte[] Encrypt(Byte[] plain, Byte[] key)
        {
            if (plain.Length > 8 || key.Length > 8)
            {
                throw new ArgumentException("Plain text and key should be 8 bytes.");
            }
            //不足8字节,补0
            if (plain.Length < 8)
            {
                plain = plain.Concat(new Byte[8 - plain.Length]).ToArray();
            }
            if (key.Length < 8)
            {
                key = key.Concat(new Byte[8 - key.Length]).ToArray();
            }

            //转为位数组 处理小端->大端
            BitArray input = new BitArray(plain.Reverse().ToArray()).Reverse();
            BitArray inputKey = new BitArray(key.Reverse().ToArray()).Reverse();
            Debug.WriteLine("[PLAIN]" + input.PrintInBinary());
            Debug.WriteLine("[KEY]" + inputKey.PrintInBinary());
            //初始置换
            input = FirstSwap(input);
            //Debug.WriteLine(input.PrintInHex());
            BitArray[] keys = new BitArray[16];
            //设置L R
            RoundPackage rounds = new RoundPackage();
            rounds.L.SetRange(0, 32, input);
            rounds.R.SetRange(0, 32, input, 32);
            //生成16轮用子密钥
            keys = GenerateKeys(inputKey);

            //16轮加密
            for (int i = 0; i < 16; i++)
            {
                rounds = Round(rounds, keys[i]);
                //Debug.WriteLine("i:{3}, L:{0},R:{1},Ki:{2}", rounds.L.PrintInBinary(), rounds.R.PrintInBinary(), keys[i].PrintInBinary(),i+1);
            }
            //Debug.WriteLine("L:{0},R:{1}", rounds.L.PrintInBinary(), rounds.R.PrintInBinary());

            BitArray output = new BitArray(64);
            //拼接:R+L
            output = rounds.R.Append(rounds.L);
            //Debug.WriteLine(output.PrintInBinary());
            //逆初始置换
            output = ReverseFirstSwap(output);
            Debug.WriteLine("[ENCRYPT]" + output.PrintInBinary());
            return output.ToByteArray();
        }
开发者ID:UlyssesWu,项目名称:Encryption,代码行数:55,代码来源:DES.cs

示例7: Decrypt

        public static byte[] Decrypt(Byte[] inputBytes, Byte[] key)
        {
            if (inputBytes.Length > 8 || key.Length > 8)
            {
                throw new ArgumentException("Encrypted text and key should be 8 bytes.");
            }
            if (inputBytes.Length < 8)
            {
                inputBytes = inputBytes.Concat(new Byte[8 - inputBytes.Length]).ToArray();
            }
            if (key.Length < 8)
            {
                key = key.Concat(new Byte[8 - key.Length]).ToArray();
            }
            //BitArray input = new BitArray(inputBytes);
            //BitArray inputKey = new BitArray(key);
            //处理小端->大端
            BitArray input = new BitArray(inputBytes.Reverse().ToArray()).Reverse();
            BitArray inputKey = new BitArray(key.Reverse().ToArray()).Reverse();
            Debug.WriteLine("[ENCRYPTED]" + input.PrintInBinary());
            Debug.WriteLine("[KEY]" + inputKey.PrintInBinary());
            input = FirstSwap(input);
            BitArray[] keys = new BitArray[16];
            RoundPackage rounds = new RoundPackage();
            rounds.L.SetRange(0, 32, input);
            rounds.R.SetRange(0, 32, input, 32);

            keys = GenerateKeys(inputKey);
            //Debug.WriteLine("L:{0},R:{1},Ki:{2}", rounds.L.PrintInHex(), rounds.R.PrintInHex(), keys[15].PrintInHex());

            for (int i = 15; i >= 0; i--)
            {
                rounds = Round(rounds, keys[i]);
                //Debug.WriteLine("L:{0},R:{1},Ki:{2}", rounds.L.PrintInHex(), rounds.R.PrintInHex(), keys[i].PrintInHex());
            }
            BitArray output = new BitArray(64);
            output = rounds.R.Append(rounds.L);
            output = ReverseFirstSwap(output);
            Debug.WriteLine("[DECRYPT]" + output.PrintInBinary());
            return output.ToByteArray();
        }
开发者ID:UlyssesWu,项目名称:Encryption,代码行数:41,代码来源:DES.cs


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