Cryptography refers to the technical science of information encryption and password cracking. The origin of cryptography can be traced back to 2 years ago. According to legend, Julius Caesar, a famous ancient Roman, sent information by password in order to prevent the enemy from intercepting information. Caesar's approach is very simple, that is, to establish a correspondence table for more than 2 Roman letters. In this way, if you don't know the password book, you can't understand even if you intercept a piece of information.
from the era of Julius Caesar to the 197s, the development of cryptography was very slow, because designers basically relied on experience. Did not apply mathematical principles. Today's cryptography is based on mathematics.
an encryption algorithm produced in 197s. Its encryption method is special, and it needs two keys: publickey and privatekey. Public key encryption, private key decryption; Private key encryption, public key decryption. This encryption algorithm is the great RSA.
To realize encryption and decryption, you should use a mathematical operation that is easy to encrypt and difficult to crack. Mod operation (clock algorithm) is used at this time.
if the prime number is used as the modulus (17), find a number 3 smaller than this modulus. Then there is the following algorithm: the x-power modulus of
3 is 17 and the result is always between 1 and 16, where 3 is the original root of 17. It is difficult to deduce the original value because it needs an experiment and is not unique to know the result. It is very difficult to reverse crack when the modulus becomes larger here. This is the discrete logarithm problem.
any given positive integer n, in <: How many positive integers = n have a coprime relationship with n?
The way to calculate this value is called Euler function, and φ(n) means
According to the above two points, if n is the product of two prime numbers P1 and P2, then:
φ(n) = φ (P1) * φ (P2) = (P1-1) * (P2-1)
If
special case of euler theorem: if two positive integers m and n are coprime and n is prime! Then φ(n) results in n-1.
Euler's law m φ(n)% n ≡ 1 (m and n are coprime)
Because of 1 k% n ≡ 1, It can be obtained that:
due to 1*m ≡ m, You can get:
verification:
? Note: in the process of conversion, m must be less than n to be valid. Greater than that is equivalent to an extra lap.
if two positive integers e and x are coprime, then the integer d must be found so that ed-1 is divisible by X ..
then: d is the modular inverse element of e to x
, the following formula can be obtained:
Assuming the quotient is k, the following formula can be obtained:
when φ(n) is x, then:
verification: m: 4, n: 15, φ(n): 8.
suppose e: 3, d?
if 3d-1 = 8k, d = (8k+1)/3 k = 4, D = 11. K=7 and d = 19
The whole derivation process is as follows: < P > Solve the confidentiality problem of key transmission.
Principle:
m e*d% n ≡ m is split by Diffie Herman key exchange.
total * * * generates 6 numbers: p1, p2, N, φ(n), E, d
Verification
M: 3, 12, n: 3 * 5 = 15, φ (n): 8,
Assuming E: 3, Then d: 11, 19
obtained by modular inverse element calculation are not public except that the public key uses n and e.
At present, the ways to get D by cracking RSA are as follows:
1. To get the private key D .. Because e*d = φ(n)*k+1. Know e and φ(n);
2 and e are known, but to get φ(n), we must know p1 and p2.
3. Because n = p1*p2. Only by decomposing the n factor can it be calculated.
at this time, it's difficult to crack.
because m of RSA is less than n, the data encrypted each time is small and needs to be encrypted in sections, which is inefficient. Key used to encrypt symmetric encryption of big data in general.
because OpenSSL (open source encryption library) is built into the Mac system, we can directly use commands on the terminal for RSA operation. There are three common instructions for RSA algorithm in OpenSSL:
generate RSA private key, The key length is 124bit
E: 65337 (public exposition)
Data is encrypted by public key, Private key decryption data
encryption:
decryption:
complete command:
enc.txt file with 128 bytes and dec.txt file with 2 bytes.
encrypting data by public key and decrypting data by private key
at this time, it becomes signature and verification.
signature:
verification:
the entire file directory is as follows: