using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GatewayTool.Protocols
{
    class XorSum16
    {
        public static string CheckSum(string message)
        {
            char[] chars = message.ToCharArray();
            int checksum = 0;
            int left = chars.Length % 2;
            int evenLength = chars.Length - left;
            for (int i = 0; i < evenLength; i += 2)
            {
                int temp = (int)chars[i] * 256 + (int)chars[i + 1];
                checksum ^= temp;
            }
            if (left != 0)
            {
                int val = (int)(chars[chars.Length - 1] << 8);
                checksum ^= val;
            }
            return Convert.ToString(checksum, 16).ToUpper();
        }
    }
}