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