Caesar code A substitution code, it is said that Caesar is one of the first ancient generals to use cryptographic letters, so this encryption method is called the Caesar password. The basic idea of Caesar's password is to encrypt and decrypt the letters by moving a certain number of digits. All letters in the clear text are replaced redact after the alphabet is shifted backwards (or forwards) by a fixed number.use Java programs to encrypt plaintext:Package com.qikeyishu.www;Public class Kaisapwd {
Public static void Main (string[] args) {
Char str[]={' 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 '};
For (char out:str) {
System.out.print (out+ "");
}
for (int i=0;i<26;i++) {
if (i<23) {
str[i]+=3;
}else{
str[i]-=23;
}
}
System.out.println ("\ n");
For (char out:str) {
System.out.print (out+ "");
}
}
}before and after encryption:
using a Java program to decrypt ciphertext:Package com.qikeyishu.www;Public class Kaisapwd {
Public static void Main (string[] args) {
Char str[]={' 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 '};
For (char out:str) {
System.out.print (out+ "");
}
for (int i=0;i<26;i++) {
if (i<23) {
str[i]-=3;
}else{
str[i]+=23;
}
}
System.out.println ("\ n");
For (char out:str) {
System.out.print (out+ "");
}
}
}before and after decryption:
Caesar password Encryption decryption--java implementation (Basic)