Programming Ideas:
1. the first definition of three string strings is S1,S2,S3, which takes advantage of a dialog box (Input string class only) to enter the strings S1.
2. use S1.length () to calculate the length of the S1.
3. Create a char array of s1.length ().
4. Use the loop to convert each character in the S1 into a char character stored in the array, and each char plus key is automatically converted to the int type and then converted to char using the coercion type.
5. Call the S2 constructor to assign a character array to S2.
6. Use the dialog box to output the encrypted string.
7. Repeat the above method to convert S2 to unencrypted before the string is stored in S3.
in the third step, the error did not find a function to convert each string in string type to an integer, and only S1.charat () converts each character to char type.
Therefore, after correction, the use of the char type array is stored at the same time as the storage of key, because key is an integer, so after the addition of the key becomes an integer (the letter corresponding to the ACII code) and then the conversion of the forced type, the integer is converted to char characters.
Import javax.swing.*; Public classProject { Public Static voidMain (String args[]) {string S1, S2, S3; S1=joptionpane.showinputdialog ("Please enter a string to encrypt:"); Charc[]; C=New Char[S1.length ()]; intA; for(intI=0; I<s1.length (); i++) {C[i]=S1.charat (i); A=c[i]+3; C[i]=(Char) A; } S2=NewString (c); Joptionpane.showmessagedialog (NULL,"the encrypted string is:"+ s2,"result", Joptionpane.plain_message); for(intI=0; I<s1.length (); i++) {C[i]=S2.charat (i); A=c[i]-3; C[i]=(Char) A; } S3=NewString (c); Joptionpane.showmessagedialog (NULL,"the decrypted string is:"+S3,"Results", Joptionpane.plain_message); }}
Cryptographic jobs in class