Simple encryption with regular expressions (C # for example)

Source: Internet
Author: User

 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.