C# Test Encryption and Decryption

 public MainWindow()
        {
          
            InitializeComponent();
            Title = getUUID();
            string s= httpGet("http://220.181.57.216/");
            //MessageBox.Show(s);
            MessageBox.Show( CheckSum("2019-9-10"));
            string sEncode=encode("0;2018-12-30");
            string sDecode=decode(sEncode );
            Title = sEncode +"-------"+ sDecode ;


        }

        int tabIndex = 0;



        string getUUID()
        {
            string code = null;
            SelectQuery query = new SelectQuery("select * from Win32_ComputerSystemProduct");
            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
            {

              //  MessageBox.Show(searcher.Get().Count.ToString());
                foreach (var item in searcher.Get() )
                {
                    using (item) code = item["UUID"].ToString();

                }
            }
            return code;


        }


        public static string encode(string str)
        {
            string htext = "";

            for (int i = 0; i < str.Length; i++)
            {
                htext = htext + (char)(str[i] + 22 );
            }
            return htext;
        }

        public static string decode(string str)
        {
            string dtext = "";

            for (int i = 0; i < str.Length; i++)
            {
                dtext = dtext + (char)(str[i] - 22 );
            }
            return dtext;
        }

        private static string CheckSum(string message)
        {
            char[] chars = message.ToCharArray();
            int checksum = 0;
            for (int i = 0; i < chars.Length; i++)
            {
                checksum += (int)chars[i];
            }
           //  checksum = (~checksum & 0xFFFF) + 0x0001;
             //return Convert.ToString(checksum, 16).ToUpper();
             return Convert.ToString(checksum, 10).ToUpper().PadLeft(5,'0');
        }

  

猜你喜欢

转载自www.cnblogs.com/wgscd/p/9663094.html
今日推荐