环境说明:
服务器端是redhat5+sybase15ase
sybase 用的字符集是sybase默认的iso_1字符集 代码页为28591
客户端以前是用pb7开发的,
现在用.net 开发客户端
问题说明:
现在有个密码字段,是经过的加密的,加密算法比较简单,把字符转为ascii码,然后用255-ascii码,再转为字符,把各字符相加存入字段中
比如,密码为666666 ,存入后,用pb或vs select 出来后为 噬噬噬
现在我想把噬噬噬反算为666666
问怎么写

解决方案 »

  1.   

    Encoding.GetEncoding(28591).GetString(bytes,0,bytes.Length)
      

  2.   

    根据专家提示
               string unicodeString = "噬噬噬";
                Encoding unicode = Encoding.Unicode;
                Encoding iso_1 = Encoding.GetEncoding(28591);
                byte[] unicodeBytes = unicode.GetBytes(unicodeString);
                ok.Text = iso_1 .GetString( unicodeBytes ,0,unicodeBytes .Length);//显示在一个按钮上看看
    那么解密算法在哪写?
      

  3.   

    从编码上转换。1楼回复给你的只是转换方法。大可不必如6楼那样测试。因为噬噬噬用Encoding.Unicode得到的结果是:
    [0x00000000] 0xca byte
    [0x00000001] 0xc9 byte
    [0x00000002] 0xca byte
    [0x00000003] 0xc9 byte
    [0x00000004] 0xca byte
    [0x00000005] 0xc9 byte
    看上去不太可能和66666扯上关系。用pb或vs select 出来后为 噬噬噬select是什么?你是说从数据库里读出来的是错的?还是pb的某个dll导出的方法是这样?
      

  4.   

    还有,测试不是这样做的。
    string unicodeString = "噬噬噬";
    这里"噬噬噬"已经是Encoding.Default下的字符串了。要测试也该用原始的byte[]来测试。
      

  5.   

    select pwd where emp where empid='0210'
    出来的结果就是"噬噬噬"
    我该怎么办呢?
      

  6.   

    select pwd where emp where empid='0210'
    -----------------------------------------
    不懂数据库相关的
    返回的是个DataTable,
    string s = dt.Rows[0][0].ToString();
    用这个s做测试
    不过和c#,pb应该没关系吧。sbase的数据库的话,看看如何读写的,有没有加密,字符集设置之类的。
      

  7.   

    66666的加密算法是这样的
    先取一个字符 也就是6 转为ascii码为54 ,然后255-54=201
    ascii码为201的字符为É 然后再取下一个字符,
    这样就把ÉÉÉÉÉÉ存入数据库中,用select pwd where emp where empid='0210'取出来后显示的为"噬噬噬"
    现在怎样才能将"噬噬噬" 转为666666
      

  8.   

    如果你能找到一个比较合适的转换过去的方法,可以修改Encoding。但是我只能写出这样的。private static void TestClick()
    {
        string str = "缮缮缮";
        byte[] bytes = Encoding.Default.GetBytes(str);
        for (int i = 0; i < bytes.Length; i++)
        {
            bytes[i] = (byte)(255 - bytes[i]);
        }
        string s = Encoding.GetEncoding(28591).GetString(bytes);
        Console.WriteLine(s);
    }按你说的方法转换也无法得到你说的三个字符。我顺着转,转出来是 缮缮缮 ,如果逆转,这样就可以了。