Home > Back-end >  Excuse me, does this problem with Java do you do
Excuse me, does this problem with Java do you do

Time:10-06

Enter a period of English letters cables, ends with a carriage return type, the message is encrypted, the letters from the cables into the following 3, the last three letters x, y, z into a, b, c,

CodePudding user response:

Define a character array
Char alp []={' a ', 'b',... , 'y', 'z'};
Encounter letters take cycle (subscript letter
Such as char c='x'
Encrypted into c=alp [(3 + (c - 'a')) % 26];

CodePudding user response:

reference 1st floor qybao response:
define a character array
Char alp []={' a ', 'b',... , 'y', 'z'};
Encounter letters take cycle (subscript letter
Such as char c='x'
Encrypted into c=alp [(3 + (c - 'a')) % 26];

Can be more about it?

CodePudding user response:

After receiving string character array, the cycle of times for the length of the subtract 3, each subscript location element +=3, cycle after the final xyz to ABC, then converted to a string

CodePudding user response:

After receiving string character array, the cycle of times for the length of the subtract 3, each subscript location element +=3, cycle after the final xyz to ABC, then converted to a string

CodePudding user response:

The server the trash back into a message card, management deleted very quickly

CodePudding user response:

import java.util.Scanner;
The class Test {
Public static void main (String [] args) {
String STR="axy";
String STRS="";
For (int x=0; xChar tem=STR. CharAt (x);
If (tem=='x') {
STRS +='a';
} else if (tem=='y') {
STRS +='b';
} else if (tem=='z') {
STRS +='c'.
} else {
STRS +=(char) + 3 (tem);
}
}
System. The out. Println (STRS);
}
}

CodePudding user response:

This is called "Caesar encryption", you put the alphabet as a closed loop will be able to understand the abstract, or do you think of watches and clocks, what time is three hours after 11 PM?

CodePudding user response:

 public class Sample {
Public static void main (String [] args) {
String s="12345 abcdefghijklmnopqrstuvwxyz67890";
The StringBuilder buf=new StringBuilder ();
For (char c: s.t oCharArray ()) {
If (c>='a' & amp; & C<='z') {//+ 3 letters to 26 letters after modulus get position, the index of the current letter + 'a' again and then get the current letter
Buf. Append ((char), (c - 'a' + 3) % 26 + 'a'));//modulus for more than 26 letters and then back to the head to locate the position of the letter
//such as letters, 27 27% 26==1, is equivalent to return to the first letter
} else {
Buf. Append (c);
}
}
System. The out. Printf (" before encryption: % s \ n ", s);
System. The out. Printf (" encrypted: % s \ n ", buf);
}
}
  • Related