Cryptographic jobs in class

Source: Internet
Author: User

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

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.