Caesar password Encryption decryption--java implementation (Basic)

Source: Internet
Author: User

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)

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.