1. Key calculation and acquisition process
The key is calculated as: first select two prime numbers p and Q, to make n=p*q.
Make k=? (n) = (p?1) (q?1), see Principle 2 analysis
Select any integer d to ensure that it is with the K coprime
Take the integer e, making [De]k=[1]k. This means that de=kt+1,t is an integer.
2, RSA encryption Algorithm principle analysis
The following analysis of its intrinsic mathematical principles, the RSA encryption algorithm will have to talk about Euler's theorem.
欧拉定理(Euler’s theorem)是欧拉在证明费马小定理的过程中,发现的一个适用性更广的定理。 首先定义一个函数,叫做欧拉Phi函数,即?(n),其中,n是一个正整数。 ?(n)=总数(从1到n?1,与n互质整数) 比如5,那么1,2,3,4,都与5互质。与5互质的数有4个。?(5)=4 再比如6,与1,5互质,与2,3,4并不互质。因此,?(6)=2 对于一个质数p来说,它和1, 2, 3, …, p – 1都互质,所以?(p)=p?1。比如?(7)=6,?(11)=10
Euler's theorem is described as follows:
Euler's theorem: if n is a positive integer, a is either a non-0 integer, and N and a coprime. So, a^? (n)? 1 can be divisible by N.
Corollary 1: If M and n are positive integers of coprime. So? (MN) =? (m)? (n)
Inference 2:[ab]n=[[a]n[b]n]n
Proof: Suppose that the remainder of a and b divided by N is c1,c2. A and B can be written as A=NT1+C1,B=NT2+C2. So, ab=n2t1t2+nt1c2+nt2c1+c1c2. So the remainder of AB divided by N is c1c2. That is [Ab]n=[a]n[b]n.
With the above theorem, the intrinsic principle of RSA algorithm can be deduced.
According to Euler's theorem, for any z, if z and N coprime, then:
[z^?(n)]n=[z^k]n=[1]n
So
[z^ (DE)]n=[z^ (kt+1)]n=[z^ (kt) *z]n=[z^kt]n*[z]n= [Z]n because [z^k]n = [1]n
The above mainly uses de=kt+1 and inference 2. Other words:
[z^(de)]n=[z]n
According to the inference of 2, there is
([z^e]n)^d=[z]n
That is, the D remainder is multiplied because its product may be greater than n, so the [Ab]n=[[a]n[b]n]n, for example, A and B are 5,n to 3, the conclusion
Therefore, the formula can be described as [([Z^e]n) ^d]n=[z]n=z, that is, the original number of the balance of the remainder, and then the remainder after the second to obtain the original number of the process of obtaining evidence.
Public encryption method, private decryption method. The key to RSA security is that it is difficult to factor the decomposition of a large integer.
3. Exercise Exercises
According to the RSA algorithm, if you select two odd p=5,q=3, the public key e=7, then the private key D is: ()
The answer resolves:
Press the RSA algorithm to find the public key and key:
(1) Select two prime p=5,q=3;
(2) Calculating n=pxq=5x3=15;
(3) calculation (p-1) x (q-1) = 8;
(4) Public key e=7 is based on ed=1 mod (p-1) x (q-1), which is 7d=1 mod 8.
Combine four options to get d=7, which is the 8=1 mod.
4. Python Code implementation
p =5q = 3e = 7n = q*pmod_value = (p-1)*(q-1)# 依据 ed = 1 mod (p-1)*(q-1) # d 现在是我们需要确定的密钥,那么逆推就是 e*d % ((p-1)*(q-1)) == 1,那么就输出d的值,因为它就是我们需要求得的密钥值for d in range(0,n): if (e*d)%mod_value==1: print dresult >> 7
"Password Safe" RSA algorithm procedure-solve key