hw--string encryption and decryption

Source: Internet
Author: User

 Packaget0817;ImportJava.util.Scanner; Public classStringencrypt { Public Static voidMain (string[] args) {Scanner scanner_1=NewScanner (system.in); String str_1=Scanner_1.nextline (); Charchpass[]=Str_1.tochararray (); Charchresu[]=New Char[Str_1.length ()]; Scanner scanner_2=NewScanner (system.in); String str_2=Scanner_2.nextline (); Charchresu2[]=Str_2.tochararray (); Charchpass2[]=New Char[Str_2.length ()];           Encrypt (Chpass,chresu);           System.out.println (Chresu);           Unencrypt (CHRESU2,CHPASS2);    System.out.println (CHPASS2); }    /** Implement string encryption and output in this function*/     Static voidEncrypt (CharAucpassword[],Charaucresult[]) {         for(inti=0;i<aucpassword.length;i++){            if(aucpassword[i]>= ' A ' &&aucpassword[i]<= ' Z ') {//lowercase Letter One (+1), then uppercase ( -32)                if(aucpassword[i]== ' z ') Aucresult[i]= ' A '; Else{Aucresult[i]=(Char) (aucpassword[i]+1-32); }            }            Else if(aucpassword[i]>= ' A ' &&aucpassword[i]<= ' Z ') {//uppercase to lowercase                 if(aucpassword[i]== ' Z ') Aucresult[i]= ' A '; Else{Aucresult[i]=(Char) (aucpassword[i]+1+32); }            }            Else if(aucpassword[i]>= ' 0 ' &&aucpassword[i]<= ' 9 ') {//Digital                 if(aucpassword[i]== ' 9 ') Aucresult[i]= ' 0 '; ElseAucresult[i]=(Char) (aucpassword[i]+1); }            ElseAucresult[i]=aucpassword[i];//other characters remain unchanged                                }            }    /** Implement string decryption and output in this function*/     Static intUnencrypt (CharResult[],Charpassword[]) {         for(inti=0;i<result.length;i++){            if(result[i]>= ' A ' &&result[i]<= ' Z ') {//lowercase letters to uppercase                if(result[i]== ' a ') Password[i]= ' Z '; Else{Password[i]=(Char) (result[i]-32-1); }            }            Else if(result[i]>= ' A ' &&result[i]<= ' Z ') {//uppercase to lowercase                if(result[i]== ' A ') Password[i]= ' Z '; Else{Password[i]=(Char) (result[i]+32-1); }            }            Else if(result[i]>= ' 0 ' &&result[i]<= ' 9 ') {//Digital                if(result[i]== ' 0 ') Password[i]= ' 9 '; ElsePassword[i]=(Char) (result[i]-1); }            ElsePassword[i]=result[i];//remain unchanged                    }//For Loop        return0; }//J decoding Function    }

Title Description

1, the input string is added and decrypted, and output.

2 Encryption methods are:

When the content is an English letter is replaced with the letter of the latter letter, while the letter conversion case, such as the letter A is replaced by B, the letter z is replaced by A;

When the content is a number, the number is added 1, such as 0 to replace the replacement 2,9 replacement 0;

Other characters do not change.

3, the decryption method is the inverse process of encryption.

Interface Description:

Implement interfaces, each of which implements 1 basic operations:

void Encrypt (char aucpassword[], char aucresult[]): Implements string encryption in this function and outputs

Description

1. The string ends with a.

2, string maximum 100 characters.

int Unencrypt (char result[], char password[]): Implement string decryption and output in this function

Description

1. The string ends with a.

2, string maximum 100 characters.

Knowledge points String
Run time limit 10M
Memory limit 128
Input

Enter a description
Enter a string of passwords to encrypt
Enter a string of password encryption

Output

Output description
Output encrypted characters
Output decrypted characters

Sample input ABCDEFG BCDEFGH
Sample output BCDEFGH ABCDEFG

hw--string encryption and decryption

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.