代码改变世界

密码轮算法,用Key来加密数据内容

2013-03-22 17:40  咒语  阅读(417)  评论(0编辑  收藏  举报
  public static byte[] KeyGear(byte[] key, byte[] source)
        {
            var keyLength = key.Length;
            var kindex = 0;
            var index = 0;
            foreach (var b in source)
            {
                var k = key[kindex];
                source[index] = Convert.ToByte(k ^ b);
                if (kindex + 1 >= keyLength) kindex = 0;
                else
                {
                    kindex++;
                }
                index++;
            }
            return source;
        }

2byte的Key,72byte的数据内容,20W次运算,约1.5s