SoFunction
Updated on 2025-03-07

C# String Processing Widget

I was addicted to security when I was in college and always wanted to write a small program that handles strings.

Unfortunately, there was not much time at that time, so I delayed until this winter vacation.

I have nothing to do during the winter vacation, so I wrote a mini program to practice and review the forms and basics.

The functions implemented are as follows:

Convert to capital

Convert to lowercase

Invert string

Match the number of occurrences of a string

Regular Match

base64 encryption

base64 decryption

ROT13 encryption and decryption

MD5 32-bit encryption

The program is still very simple, without robustness, and no input verification.

Create a bug with your heart (Bitsin

Also, please don’t complain about my variable naming and method naming. If you didn’t learn pinyin since elementary school, you will definitely not understand it :)

Because at the beginning, I did this in a blind test project.

I'm really too lazy to translate

There is a method to convert to uppercase and lowercase

(());//Convert to capital(());//Convert to lowercase

Output reverse string

public static void fanxiang(string s)
  {
   char[] arrey = ();
   StringBuilder s1 = new StringBuilder("");
   for (int i =  - 1; i >= 0; i--)
   {
    ((arrey[i]));
   }
   ("The reverse string is{0}",s1);
  }

View the number of a short string in it

public static void pipei(string s)
  {
   int count = 0;
   int i;
   ("Please enter a short string");
   string s2 = ();
   while ((i=(s2)) >= 0)
   {
    count++;
    s = (i + );
   }
   ("Appears in the string{0}Second-rate{1}", count, s2);
  }

Regular Match

I have never learned the knowledge of regularity, and I have read a lot of them online, most of them talk about regularity rather than regularity. I wrote this for about a day and I still have a bug now.

When there is no matching result, or is it matched to empty? It will cause multiple lines to break. I also forgot how I tested the bug at that time.

Anyone who has any ideas can tell me.

public static void zzpipei(string s)
  {
   ("Please enter regular expression");
   string zz = ();
   Regex re = new Regex(zz);
   string s2 = "";
   if ((s))
   {
    ("Match Successfully");
    MatchCollection mc = (s);
    foreach (Match ma in mc)
    {
     s2 += ;
     s2 += ("\r\n");
    }
    ("One behavior, one match result");
    (s2);
   }
   else
   { ("No matching result"); }
  }

base64 encryption

The method used is also in-house, and the encryption of Chinese characters is different from that of some websites.

 public static void basejiami(string s)
  {
   byte[] bytes = (s);
    ("Stringbase64Encrypted as{0}", Convert.ToBase64String(bytes));
  }

base64 decryption

 public static void basejiemi(string s)
  {
   byte[] bytes = Convert.FromBase64String(s);
    ("Stringbase64Decrypted as{0}", (bytes));
  }

ROT13 encryption and decryption

ROT13 is a simple replacement code. ROT13 is also a variant of Caesar Encryption, which was developed in ancient Rome in the past.

ROT13 replaces 13 bits backwards, that is, A is converted to N, B is converted to O and so on.

The Caesar password is to replace 3 digits backwards. Change this method can also achieve the explosion of Caesar's password, and this method is case-sensitive.

ROT13 is its own reversal; that is, to restore ROT13, you can use the same encryption algorithm, so the same operation can be re-encrypted and decrypted.

This algorithm does not provide real cryptographic protection, so it should not be applied to purposes that require protection. It is often regarded as a typical example of weak encryption.

public static void rotjm(string s)
  {
   string jmzf = "";//Decrypt the encrypted string   char[] arrey = ();
   ("The string length is{0}", );
   for (int i = 0; i < ; i++)
   {
    int zfcode = (int)arrey[i];
    if (zfcode >= 97 && zfcode <= 109)
     zfcode = zfcode + 13;
    else if (zfcode >= 110 && zfcode <= 122)
     zfcode = zfcode - 13;
    else if (zfcode >= 65 && zfcode <= 77)
     zfcode = zfcode + 13;
    else if (zfcode >= 78 && zfcode <= 90)
     zfcode = zfcode - 13;
    jmzf = jmzf + (char)zfcode;
   }
   ("The result is{0}", jmzf);
  }

Replace string

public static void thzf(string s)
  {
   ("Please enter the string you want to be replaced");
   string str1 = ();
   ("Please enter the string you want to replace");
   string str2 = ();
   ((str1, str2));
  }

32-bit MD5 encryption

public static void md5jm(string s)
  {
   MD5 md5 = new MD5CryptoServiceProvider();
   //Encode characters into byte sequence   byte[] data = (s);
   byte[] md5data = (data);
   ();
   //Transfer the encrypted array and encrypted bytes. This method is 32-bit encryption   string str = "";
   for (int i = 0; i < ; i++)
   {
    str += md5data[i].ToString("x").PadLeft(2, '0');
   }
   ("The encryption result is{0}",str);
  }

My program, using .NET framework 4.0.

download

The above is all the content of this article. I hope that the content of this article will help you study or work. I also hope to support me more!