C#异或算法

来源:互联网 发布:生化危机6武器数据 编辑:程序博客网 时间:2024/05/22 16:39
string fen = Helper.Yuan2Fen(txtTotalAmt);string fullAmt = fen.PadLeft(12,'0');string hexTotalAmt = ByteUtil.StringToHex(fullAmt,Encoding.Default);//e.g. 02 00 18 03 01 31 31 31 31 31 31 31 35 1c 30 30 30 30 30 30 30 30 30 30 30 31 1c 03 1CStringBuilder data = new StringBuilder();data.Append("00 18 03 01 31 31 31 31 31 31 31 35 1c ");data.Append(hexTotalAmt);data.Append(" 1c 03 ");byte[] bytes = ByteUtil.HexToByte(data.ToString(), Encoding.Default);byte b = bytes[0];for (int i = 1; i < bytes.Length; i++){    if (bytes[i] == 32)    {        continue;    }    int a = bytes[i] ^ b;    b = byte.Parse(a.ToString());}data.Append(ByteUtil.ByteToHexStr(new byte[]{b}));data.Insert(0,"02 ");
原创粉丝点击