Java Program--Caesar encryption

Source: Internet
Author: User

The ancient Roman Emperor Caesar used the following methods to encrypt military intelligence during the war: please write a program that uses the above algorithm to encrypt or decrypt the user input of the English string requirements design ideas, program flowchart, source code, results. Design idea: Enter a string, and then each character is taken separately, and the algorithm of the character is added 3, forced to convert to the following 3 characters, the final output. Program Flowchart: Source code:
 Packagetest;Importjava.util.*;//Reference Util Package Public classCaesar { Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner A =NewScanner (system.in);//Initialize ScannerString Cipher,result;//Create a stringSystem.out.println ("Enter the English string:");//OUTPUT Hint Wordcipher = A.nextline ();//inputresult= "";//Initialize string        inti;  for(i=0; I<cipher.length (); i++) {//length of the loop stringResult + = (Char) (Cipher.charat (i) +3);//take each character out of the string, move it back, and finally connect} System.out.println ("After encryption:" +result);//Output    }}

Operation Result:

Java Program--Caesar encryption

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.