Classical cipher Algorithm Caesar (CAESAR) password, also known as cyclic shift password

Source: Internet
Author: User

Classical cryptography algorithm has been widely used, mostly simpler, using manual and mechanical operation to achieve encryption and decryption. Its main application object is the text information, uses the cipher algorithm to realize the text information encryption and the decryption. Two common classical cryptographic algorithms are described below to help readers create a preliminary impression of a cryptographic algorithm.

1. Alternate password

Instead, the principle of an alternative cipher is to encrypt by using an alternative method, which is to create a ciphertext by replacing the plaintext with other letters, numbers, or matches. Here each plaintext letter corresponding to the ciphertext may be one or more than one. The receiver can get the clear text by reverse replacement of the cipher. There are five forms of alternative passwords:

1 single table instead

That is, a simple substitution cipher or a single character in the plaintext alphabet corresponds to a character in the cipher table. This is the simplest method of all encryption.

More than 2 yards to replace

is to map the characters in the plaintext alphabet to more than one character in the dense-text master table. Multi-code simple replacement as early as in 1401 by the Duchymantua company to use. In English, vowel letters appear most frequently, and one way to reduce the frequency of corresponding ciphertext is to use multiple codes, such as e may be replaced by 5, 13, or 25 ciphertext.

3 multi-tone code instead

is to replace more than one literal character with a secret character. For example, the letters "I" and "J" correspond to "K", "V" and "w" instead of "L" the oldest of these multiple-letter encryption is found in the 1563 by Bo his "steganography evaluation" (De Furtiois literarum notis) book.

More than 4 tables instead

That consists of a plurality of simple substitutes, that is, the use of two or more alternative tables. For example, using a substitution cipher with 5 simple substitution tables, the first letter of the plaintext replaces the table with the first, the second with the second, the third, and so on, using the five tables instead of the table. Multiple table replacement password was invented by Leon Batista in 1568, and the famous Virginia and Beaufort passwords are multiple tables instead of passwords.

Below we introduce a typical single form substitution password--Caesar (Caesar) password, also called the cyclic shift password. The encryption method is to replace each letter in the plaintext with the letter r of the letter in the alphabet to achieve the purpose of encryption. Its encryption process can be expressed as the following function:


where M is the number of letters in the alphabet for the clear letter, N is the number of the letters in the alphabet, K is the key, and the number of positions in the alphabet for the secret text mother.

For example: for the plaintext letter H, the number of positions in the alphabet is 8, set, then the upper-form computed by the cipher is L, the calculation process is as follows:


The code is:

#include <iostream> using namespace std;
        # define N-int searchnum (char t) {char R;
        Char str[26];
        for (int i=1,r= ' A '; i<=n;i++,r++) {str[i]=r;
        for (int i=1;i<=n;i++) {if (T==str[i]) return i;
        } char SearchChar (int t) {char R;
        Char str[26];
        for (int i=1,r= ' A '; i<=n;i++,r++) {str[i]=r;
        for (int i=1;i<=n;i++) {if (t==i) return str[i];
    } void Jiami () {char str[50];
    int k;
    cout<< "Please enter your key:" <<endl;
    int m;
    char s;
    cin>>k;
    cout<< "Please enter your clear text:" <<endl;
    cin>>str;
        for (int i=0;str[i]!= '; i++) {int a,b;
        Char Ch=str[i];
        int M=searchnum (CH);
        A=m+k;
        b=a%26;
        Char C=searchchar (b);
    Str[i]=c;
    cout<< "Your redaction is:" <<endl; Forint i=0;str[i]!= ' n ' i++) {cout<<str[i];
    } void Jiemi () {char str[50];
    int k;
    cout<< "Please enter your key:" <<endl;
    int m;
    char s;
    cin>>k;
    cout<< "Please enter your ciphertext:" <<endl;
    cin>>str;
        for (int i=0;str[i]!= '; i++) {int a,b;
        Char Ch=str[i];
        int M=searchnum (CH);
            if (m<k) {a=m+n-k;
        b=a%n;
            else if (m>k) {a=m-k;
        b=a%n;
        else {b=n;
        } char C=searchchar (b);
    Str[i]=c;
    cout<< "Your clear text is:" <<endl;
    for (int i=0;str[i]!= '; i++) {cout<<str[i];
    int main () {int choice;
    cout<< "Please enter your choice:" <<endl; cout<< "1. Encryption; 2. Decryption;"
    <<endl;
    cin>>choice;
            Switch (choice) {case 1:jiami ();
        Break
 Case 2:jiemi ();           Break
    Default:break;
    }//cout << Searchnum (s) << Endl;
return 0; }


Implementing encryption and decryption



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.