Public stringEncrypt (stringPwdstringKey ="0") {List<string> keys =Newlist<string> {"0","1","2","3","4","5","6","7","8","9" }; intCounter =0; if(Key! ="0") { foreach(CharIinchkey) {Keys[counter]=i.tostring (); Counter++; }} List<string> Secret =Newlist<string> {"Blow","Extinguish","Read","Book","Light","a","Body","All","is a","Month" }; for(intj =0; J <Ten; J + +) {pwd=Regex.Replace (pwd, keys[j], secret[j]); } returnpwd; }
1. First, create a new keys list as a list of keys in which the characters in key (keys) are read into the keys (foreach implementation)
2. Set the replacement character list secret, (because there are 10 numbers encrypted here, and because the password setting requires the mixing of case and number special characters, so the encryption substitution character is expressed in Chinese characters)
3. Using regular expressions, through the loop, and then replace the sequence, it should be noted here, each time after the end of the loop after the value of the PWD as a parameter, otherwise you can not achieve all the replacement
At this point, encryption is complete.
The decryption function code is as follows (principle equivalent):
Simple encryption with regular expressions (C # for example)