"Huawei OJ" "023-string plus decryption"

Source: Internet
Author: User

"Huawei OJ" "Algorithm Total chapter" "Huawei OJ" "023-string Plus decryption" "Project Download" topic description
1、对输入的字符串进行加解密,并输出。2加密方法为:当内容是英文字母时则用该英文字母的后一个字母替换,同时字母变换大小写,如字母a时则替换为B;字母Z时则替换为a;当内容是数字时则把该数字加1,如0替换1,1替换2,9替换0;其他字符不做变化。3、解密方法为加密的逆过程。接口描述:实现接口,每个接口实现1个基本操作:    void encrypt (char aucPassword[], char aucResult[]):在该函数中实现字符串加密并输出说明:    1、字符串以\0结尾。    2、字符串最长100个字符。    int unEncrypt (char result[], char password[]):在该函数中实现字符串解密并输出说明:    1、字符串以\0结尾。    2、字符串最长100个字符。
Enter a description
输入说明输入一串要加密的密码输入一串加过密的密码
Output description
输出说明输出加密后的字符输出解密后的字符
Input example
abcdefgBCDEFGH
Output example
BCDEFGHabcdefg
Algorithm implementation
ImportJava.util.Scanner;/** * Author: Wang Junshu * DATE:2015/12/23 13:31 * All rights Reserved!!! */ Public  class Main {     Public Static void Main(string[] args) {Scanner Scanner =NewScanner (system.in);//Scanner Scanner = new Scanner (Main.class.getClassLoader (). getResourceAsStream ("Data.txt"));         while(Scanner.hasnext ())            {String input = Scanner.nextline ();            SYSTEM.OUT.PRINTLN (Encrypt (input));            input = Scanner.nextline ();        SYSTEM.OUT.PRINTLN (Unencrypt (input));    } scanner.close (); }/** * String Decryption * * @param S * @return  * *    Private StaticStringUnencrypt(String s) {Char[] Mask = {{' Z ',' A ',' B ',' C ',' d ',' E ',' F ',' G ',' h ',' I ',' J ',' K ',' l ',' m ',' n ',' O ',' P ',' Q ',' R ',' s ',' t ',' u ',' V ',' W ',' x ',' y '},                {' Z ',' A ',' B ',' C ',' D ',' E ',' F ',' G ',' H ',' I ',' J ',' K ',' L ',' M ',' N ',' O ',' P ',' Q ',' R ',' S ',' T ',' U ',' V ',' W ',' X ',' Y '},                {' 9 ',' 0 ',' 1 ',' 2 ',' 3 ',' 4 ',' 5 ',' 6 ',' 7 ',' 8 '}        };returnConvert (S, mask); }/** * String Encryption * * @param S * @return  */    Private StaticStringEncrypt(String s) {Char[] Mask = {{' B ',' C ',' d ',' E ',' F ',' G ',' h ',' I ',' J ',' K ',' l ',' m ',' n ',' O ',' P ',' Q ',' R ',' s ',' t ',' u ',' V ',' W ',' x ',' y ',' Z ',' A '},                {' B ',' C ',' D ',' E ',' F ',' G ',' H ',' I ',' J ',' K ',' L ',' M ',' N ',' O ',' P ',' Q ',' R ',' S ',' T ',' U ',' V ',' W ',' X ',' Y ',' Z ',' A '},                {' 1 ',' 2 ',' 3 ',' 4 ',' 5 ',' 6 ',' 7 ',' 8 ',' 9 ',' 0 '}        };returnConvert (S, mask); }/** * Convert a string based on a mask table * * @param S * @param mask * @return  */    Private StaticStringConvert(String S,Char[] mask) {StringBuilder builder =NewStringBuilder (S.length ()); for(inti =0; I < s.length (); i++) {Charc = S.charat (i);if(c >=' A '&& C <=' Z ') {Builder.append (mask[0][c-' A ']); }Else if(c >=' A '&& C <=' Z ') {Builder.append (mask[1][c-' A ']); }Else{Builder.append (mask[2][c-' 0 ']); }        }returnBuilder.tostring (); }}

"Huawei OJ" "023-string plus 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.