Cryptography shift Password

Source: Internet
Author: User
Tags ranges

For example:
1. Clear the code -- get the password through the key -->. The password here is what the ciphertext means.
2. alphabet: The table of a single letter unit in the plaintext. the English letters here are not generally ABCD. They may be 8-bit, 16-bit, 32-bit, or only some letters, such as ~ Z.
......
  
  
Shift password introduction:
  
The shift password can be traced back to ancient Rome at the earliest. <Galu war note> it describes how Caesar used a password to transmit information, that is, the so-called "Caesar password ", it is an alternative password. It is used to encrypt letters by pushing the three digits in order. For example, you can change letter A to letter D and letter B to letter e. this is a simple encryption method. The density of this password is very low. It can be deciphered simply by counting the word frequency. It is also called "shift password ", however, the number of mobile devices is not necessarily three.
  
Although the shift password is very simple, it is the foundation for us to move towards a more advanced password. Therefore, we hope you can take a closer look at the basic knowledge below.
  
Before detailed introduction, we need to know some mathematical knowledge required by cryptography.
  
1. alphabet: The table of a single letter unit in the plaintext. For example:
  
Z26: it is a commonly used alphabet based on 26 uppercase English letters. Here, the value starts from 0 and ends with 25, instead of using its ASCII value, to facilitate computation.
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
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20 21 22 23 24 25
For example, the plaintext jackozoo value is 9 0 2 10 14 14 14 14. Each character occupies one letter in the alphabet.
  
Z2 ~ 8: z256. this is a common alphabet, that is, byte stream encryption. The Alphabet ranges from 00 ~ FF contains two 8 Letter elements.
  
For example, the plaintext jackozoo code value (ANSI Code) is 4A 41 43 4B 4f 5A 4f 4f.
Plaintext love your whole life (ANSI code) code value is B0 AE C4 E3 D2 BB C9 fa D2 BB ca C0.
  
Z2 ~ 16: that is, z65536. this alphabet is often used in word stream encryption. The Alphabet ranges from 0000 ~ A total of 2 FFFF 16 Letter elements.
  
For example, the plaintext jackozoo (ANSI) code value is 4a41 434b 4f5a 4f4f, which occupies 4 letter units.
B0ae c4e3 d2bb c9fa d2bb cac0.6 alphanumeric units.
  
Z2 ~ 32: The Alphabet ranges from 00000000 ~ Ffffffff contains 32 Letter units in total. It is often used for dual-character stream encryption.
  
For example, the plaintext jackozoo (ANSI) code value is 4a41434b 4f5a4f4f, which occupies two letter units.
The plaintext value of your lifetime (ANSI) is b0aec4e3 d2bbc9fa d2bbcac0, which occupies three letter units.
  
Note: The aforementioned byte streams, word streams, and dual-word streams are only relative to the alphabet selected during encryption, because any information is stored in binary streams on the computer.
  
  
2. modulo n plus and modulo n multiplication:
Life N is a positive integer, And the alphabet ZN = {0, 1, 2... n-1 }. if a and B belong to Zn, the modulo n of A + B mod n is defined as A and B.
Similarly, AB mod n is a modulo n multiplication of A and B.
  
  
Shift password:
The principle of the shift password system (Caesar cipher) can be described in a + B mod 26. The shift password system includes:
  
Plaintext: iamjackozoo
Key: K = 2
Ciphertext: kcolcemqbqq
  
Each letter unit in the ciphertext is obtained by repeating the three-digit right shift of the plaintext in the alphabet.
  
This encryption rule can be summarized as follows: Y = (x + 3) mod 26. X, Y, z26. X is the ciphertext, and Y is the plaintext.
  
  
To sum up, the shift password has the following concepts:
  
(This is for the Z26 alphabet)
1) plaintext alphabet Z26
2) key K = A belongs to Z26
3) encrypted transformation y = (x + a) mod 26, X, Y, Z26
4) decryption and transformation x = (Y-a) mod 26, X, Y, Z26
  
Let's look at an example:
Example 1: In the known shift password, the plaintext is hijackozoo, the alphabet is Z26, and the secret key is k = 9. please encrypt it.
  
Solution: The hijackozoo code value obtained from the Z26 alphabet is:
7 8 9 0 2 10 14 25 14 14 (10 letter units in total)
Perform the Y = (x + k) mod 26 operation on each letter unit:
→ 16 17 18 9 11 19 23 8 23 23
Therefore, the ciphertext is:
→ Qrsjltxixx
  
Example 2: The plaintext in the known shift password is to love your whole life, and the alphabet is Z2 ~ 8. The key is 0x99. please encrypt it.
  
Solution: the Z2 ~ 8. The code for loving you for the whole of life is:
B0 AE C4 E3 D2 BB C9 fa D2 BB ca C0 (12 letters in total)
Perform the Y = (x + k) mod 0x100 operation on each letter unit:
→ 49 47 5d 7C 6B 54 62 93 6B 54 63 59
Therefore, the ciphertext is:
IG] | KTB rjtcy.

 

 

==================================

 

 

Reference Code

 

 

# Include <stdio. h>
Void code (char * P, int key)
{
While (* P! = '/0 ')
{
* P = 97 + (* p-97 + key) % 26;
P ++;
}
}
Void uncode (char * P, int key)
{
While (* P! = '/0 ')
{
* P = 97 + (* p-71-key) % 26;
P ++;
}
}
Main ()
{
Char STR [100];
Int N, key;
Printf ("Input key :");
Scanf ("% d", & Key );
Printf ("input 1 encrypted, input 2 decrypted :");
Scanf ("% d", & N );
Printf ("input string :");
Scanf ("% s", STR );
If (n = 1)
{
Code (STR, key );
Printf ("ciphertext: % s/n", STR );
}
Else if (n = 2)
{
Uncode (STR, key );
Printf ("Original: % s/n", STR );
}
}

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.