'李' 字对应的整数为26446, 二进制表示就为110011101001110,  对'李' 字用 base64进行编码得到wO4NCg==, 哪位能解释下为什么不??小弟先谢过了!

解决方案 »

  1.   

    UP + 学习 + 接分UP + 学习 + 接分UP + 学习 + 接分
      

  2.   


    base64编码类------源代码(C#) 
    《世界计算机》IT.ICXO.COM ( 日期:2004-12-29 15:59) --------------------------------------------------------------------------------
     
     
    using system;namespace shapbse64
    {/// 
    /// 有关base64编码算法的相关操作
    ///by 自由奔腾(wgscd)
    /// 
    public class sbase64
    {
    public sbase64()
    {
    //
    // todo: 在此处添加构造函数逻辑
    //
    }
    //--------------------------------------------------------------------------------
    /// 
    /// 将字符串使用base64算法加密
    /// 
    /// 待加密的字符串
    /// system.text.encoding 对象,如创建中文编码集对象:system.text.encoding.getencoding(54936)
    /// 加码后的文本字符串
    public static string encodingforstring(string sourcestring,system.text.encoding ens)
    {
    return convert.tobase64string(ens.getbytes(sourcestring));
    }
    /// 
    /// 将字符串使用base64算法加密
    /// 
    /// 待加密的字符串
    /// 加码后的文本字符串
    public static string encodingforstring(string sourcestring)
    {
    return encodingforstring(sourcestring,system.text.encoding.getencoding(54936));
    }
    /// 
    /// 从base64编码的字符串中还原字符串,支持中文
    /// 
    /// base64加密后的字符串
    /// system.text.encoding 对象,如创建中文编码集对象:system.text.encoding.getencoding(54936)
    /// 还原后的文本字符串
    public static string decodingforstring(string base64string,system.text.encoding ens)
    {
    /**
    * ***********************************************************

    * 从base64string中取得的字节值为字符的机内码(ansi字符编码)
    * 一般的,用机内码转换为汉字是公式:
    * (char)(第一字节的二进制值*256 第二字节值)
    * 而在c#中的char或string由于采用了unicode编码,就不能按照上面的公式计算了
    * ansi的字节编和unicode编码不兼容
    * 故利用.net类库提供的编码类实现从ansi编码到unicode代码的转换

    * getencoding 方法依赖于基础平台支持大部分代码页。但是,对于下列情况提供系统支持:默认编码,即在执行此方法的计算机的区域设置中指定的编码;little-endian unicode (utf-16le);big-endian unicode (utf-16be);windows 操作系统 (windows-1252);utf-7;utf-8;ascii 以及 gb18030(简体中文)。
    *
    *指定下表中列出的其中一个名称以获取具有对应代码页的系统支持的编码。
    *
    * 代码页 名称 
    * 1200 “utf-16le”、“utf-16”、“ucs-2”、“unicode”或“iso-10646-ucs-2” 
    * 1201 “utf-16be”或“unicodefffe” 
    * 1252 “windows-1252” 
    * 65000 “utf-7”、“csunicode11utf7”、“unicode-1-1-utf-7”、“unicode-2-0-utf-7”、“x-unicode-1-1-utf-7”或“x-unicode-2-0-utf-7” 
    * 65001 “utf-8”、“unicode-1-1-utf-8”、“unicode-2-0-utf-8”、“x-unicode-1-1-utf-8”或“x-unicode-2-0-utf-8” 
    * 20127 “us-ascii”、“us”、“ascii”、“ansi_x3.4-1968”、“ansi_x3.4-1986”、“cp367”、“csascii”、“ibm367”、“iso-ir-6”、“iso646-us”或“iso_646.irv:1991” 
    * 54936 “gb18030” 
    *
    * 某些平台可能不支持特定的代码页。例如,windows 98 的美国版本可能不支持日语 shift-jis 代码页(代码页 932)。这种情况下,getencoding 方法将在执行下面的 c# 代码时引发 notsupportedexception:
    *
    * encoding enc = encoding.getencoding(shift-jis); 
    *
    * **************************************************************/
    //从base64string中得到原始字符
    return ens.getstring(convert.frombase64string(base64string));
    }
    /// 
    /// 从base64编码的字符串中还原字符串,支持中文
    /// 
    /// base64加密后的字符串
    /// 还原后的文本字符串
    public static string decodingforstring(string base64string)

    return decodingforstring(base64string,system.text.encoding.getencoding(54936));
    }
    //--------------------------------------------------------------------------------------/// 
    /// 对任意类型的文件进行base64加码
    /// 
    /// 文件的路径和文件名
    /// 对文件进行base64编码后的字符串
    public static string encodingforfile(string filename)
    {
    system.io.filestream fs=system.io.file.openread(filename);
    system.io.binaryreader br= new system.io.binaryreader(fs);/*system.byte[] b=new system.byte[fs.length];
    fs.read(b,0,convert.toint32(fs.length));*/
    string base64string=convert.tobase64string(br.readbytes((int)fs.length));
    br.close();
    fs.close();
    return base64string;
    }/// 
    /// 把经过base64编码的字符串保存为文件
    /// 
    /// 经base64加码后的字符串
    /// 保存文件的路径和文件名
    /// 保存文件是否成功
    public static bool savedecodingtofile(string base64string,string filename)
    {
    system.io.filestream fs=new system.io.filestream(filename, system.io.filemode.create);
    system.io.binarywriter bw = new system.io.binarywriter(fs);
    bw.write(convert.frombase64string(base64string));
    bw.close();
    fs.close();
    return true;
    }
    //-------------------------------------------------------------------------------/// 
    /// 从网络地址一取得文件并转化为base64编码
    /// 
    /// 文件的url地址,一个绝对的url地址
    /// system.net.webclient 对象
    /// 
    public static string encodingfilefromurl(string url,system.net.webclient objwebclient)
    {
    return convert.tobase64string(objwebclient.downloaddata(url));
    }
    /// 
    /// 从网络地址一取得文件并转化为base64编码
    /// 
    /// 文件的url地址,一个绝对的url地址
    /// 将文件转化后的base64字符串
    public static string encodingfilefromurl(string url)
    {
    //system.net.webclient mywebclient = new system.net.webclient();
    return encodingfilefromurl(url,new system.net.webclient());
    }
    }
    }