RSA算法原理(1)阮一峰参考: http://www.ruanyifeng.com/blog/2013/06/rsa_algorithm_part_one.html
RSA算法原理(2)阮一峰参考: http://www.ruanyifeng.com/blog/2013/07/rsa_algorithm_part_two.html
扩展欧几里得Python实现 : http://www.cnblogs.com/7hat/p/3406494.html
Python调用C: https://www.cnblogs.com/lovephysics/p/7237227.html
gcc -o libpycall.so -shared -fPIC pycall.c
我自己写的加密算法,待完善.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import random
p=61
q=53
n = p*q
Euler = (p-1)*(q-1)
# e = random.sample(range(1,Euler,1)
# e = random.randint(1,Euler)
e = 17
def extendedGCD1(a, b):
# a*xi + b*yi = ri
if b == 0:
return (1, 0, a)
(x, y, r) = extendedGCD1(b, a%b)
tmp = x
x = y
y = tmp - (a/b) * y
return (x, y, r)
x = int(extendedGCD1(e,Euler)[0])
y = int(extendedGCD1(e,Euler)[1])
print(x,y)
if x>y:
d = x
else:
d = y
public_key = [n,e]
private_key = [n,d]
print(public_key,private_key)
#m是要发送的信息
m = 65
def encrypt(m,e,n):
return m**e % n
print("加密后的信息为:",encrypt(m,e,n))