Haha, I just started to learn C # recently. It feels good.
The following sectionCodeIs implemented in C #, mainly to encrypt and decrypt strings.
//Source code
// Encrypt and decrypt a string
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace study_test4
{
Class Program
{
Static void main (string [] ARGs)
{
String s; // defines storage input string variables
Int L; // defines the variable that stores the string length.
/* Encrypt the input string */
Console. writeline ("Please input a string :");
S = console. Readline (); // input string
L = S. length; // calculate the string length
Char [] arr = new char [l]; // defines an array of characters to store encrypted strings.
Arr [0] = s [L-1]; // stores the end character of the input string to the first position of the character array
For (INT I = 1; I <L; I ++)
Arr [I] = (char) (INT) (s [I-1]) + 3);/* from the second character of the input string to the second-to-last character of the input string,
* Add three characters in sequence, and store the remaining positions in the character array */
Console. Write ("encrypted :");
For (INT I = 0; I <L; I ++)
Console. Write ("{0}", arr [I]); // output encrypted characters
/* Decrypt the encrypted string */
Char [] arr_decode = new char [l];
Arr_decode [L-1] = arr [0];
For (INT I = 1; I <L; I ++)
Arr_decode [I-1] = (char) (INT) (ARR [I])-3 );
Console. Write ("decrypted :");
For (INT I = 0; I <L; I ++)
Console. Write ("{0}", arr_decode [I]); // output encrypted characters
Console. Readline (); // stop the console on the display page.
}
}
}
In the process of learning C #, I am deeply aware that a good piece of code must be annotated, because the code written is not just for myself. So in order to develop the habit of writing comments, although the Code is very simple, I also commented out them one by one.
I hope you can help us with the correction. Thank you, O (∩ _ ∩) O.