zoukankan      html  css  js  c++  java
  • 传奇3外挂加密解密过程(C#)版

    加密算法1:
            public string Base64Encode(string source)
             {
                 byte[] a1,a2,a3;
                 BitArray b1,b2,b3;
                 a1 = Encoding.Default.GetBytes(source);
                if (a1.Length % 3 == 0) a2 = new byte[a1.Length*4/3];
                else a2 = new byte[a1.Length*4/3+1];
                 a3 = new byte[1];
                 b1 = new BitArray(a1);
                 b2 = new BitArray(6);
                 b3 = new BitArray(b1.Length);
                for (int i = 0, k = b1.Length / 8; i < k; i++) 
                 {
                    for(int j=7;j>=0;j--)b3[i*8+j]=b1[i*8+7-j];
                 }
                for (int i = 0,k=b1.Length/6; i < k; i++)
                 {
                    for (int j = 0; j < 6; j++)
                     {
                         b2[5-j] = b3[i * 6 + j];
                     }
                     b2.CopyTo(a3,0);
                     a2[i] = a3[0];
                 }
                if (a1.Length % 3 == 1) a2[a2.Length - 1] = (byte)((byte)(a1[a1.Length - 1] << 6) >> 2);
                else if (a1.Length % 3 == 2) a2[a2.Length - 1] = (byte)((byte)(a1[a1.Length - 1] << 4 )>> 2);
                for (int i=0; i < a2.Length; i++) a2[i] = (byte)(a2[i] + 0x3c);
                return Encoding.Default.GetString(a2);
             }
    
    加密算法2:
    
            public string Base64Encode(string source)
             {
                 byte[] a1, a2;
                 a1 = Encoding.Default.GetBytes(source);
                if (a1.Length % 3 == 0) a2 = new byte[a1.Length * 4 / 3];
                else a2 = new byte[a1.Length * 4 / 3 + 1];
                for (int i = 0, k = a1.Length / 3; i < k; i++) 
                 {
                     a2[i*4] = (byte)(a1[i*3] >> 2);
                     a2[i*4 + 1] = (byte)((byte)((byte)(a1[i*3] << 6) >> 2) + (byte)(a1[i*3 + 1] >> 4));
                     a2[i*4 + 2] = (byte)((byte)((byte)(a1[i*3 + 1] << 4) >> 2) + (byte)(a1[i*3 + 2] >> 6));
                     a2[i*4 + 3] = (byte)((byte)(a1[i*3 + 2] << 2) >> 2);
                 }
                if (a1.Length % 3 == 1)
                 {
                     a2[a2.Length - 2] = (byte)(a1[a1.Length - 1] >> 2);
                     a2[a2.Length - 1] = (byte)((byte)(a1[a1.Length - 1] << 6) >> 2);
                 }
                else
                    if (a1.Length % 3 == 2)
                     {
                         a2[a2.Length - 3] = (byte)(a1[a1.Length - 2] >> 2);
                         a2[a2.Length - 2] = (byte)((byte)((byte)(a1[a1.Length - 2] << 6) >> 2) + (byte)(a1[a1.Length - 1] >> 4));
                         a2[a2.Length - 1] = (byte)((byte)(a1[a1.Length - 1] << 4) >> 2);
                     }
                for (int i = 0; i < a2.Length; i++) a2[i] = (byte)(a2[i] + 0x3c);
                return Encoding.Default.GetString(a2);
             }
    
    解密算法:
    
            public string Base64Decode(string source) 
             {
                 byte[] a1, a2;
                 a1 = Encoding.Default.GetBytes(source);
                 a2 = new byte[a1.Length * 3 / 4];
                for (int i = 0; i < a1.Length; i++) a1[i] = (byte)(a1[i] - 0x3c);
                for (int i = 0, k = a1.Length / 4; i < k; i++)
                 {
                     a2[i * 3] = (byte)((byte)(a1[i * 4] << 2) + (byte)(a1[i * 4 + 1] >> 4));
                     a2[i * 3 + 1] = (byte)((byte)(a1[i * 4 + 1] << 4) + (byte)(a1[i * 4 + 2] >> 2));
                     a2[i * 3 + 2] = (byte)((byte)(a1[i * 4 + 2] << 6) + a1[i * 4 + 3]);
                 }
                if (a2.Length % 3 == 2)
                 {
                     a2[a2.Length - 2] = (byte)((byte)(a1[a1.Length - 3] << 2) + (byte)(a1[a1.Length - 2] >> 4));
                     a2[a2.Length - 1] = (byte)((byte)(a1[a1.Length - 2] << 4) + (byte)(a1[a1.Length - 1] >> 2));
                 }
                else
                if (a2.Length % 3 == 1) a2[a2.Length - 1] = (byte)((byte)(a1[a1.Length - 2] << 2) + (byte)(a1[a1.Length - 1] >> 4));
                return Encoding.Default.GetString(a2);
             }
    
  • 相关阅读:
    分布式文件系统-glusterfs
    Centos7防火墙使用
    Centos7使用Python3
    ldap认证服务的搭建
    kafka使用
    Python基本数据类型
    Linux 内核参数优化
    MHA+atlas(数据库的高可用与读写分离)
    插槽(slot)
    常用组件通信方式
  • 原文地址:https://www.cnblogs.com/grantvip/p/1302466.html
Copyright © 2011-2022 走看看