一、下载ez_setup.py(http://peak.telecommunity.com/dist/ez_setup.py)
二、用python解释执行它 (如使用IDLE打开该py文件,按F5解释执行)
三、安装完成后,会在scripts文件夹下生成几个exe可执行文件。(如: D:\Python27\Scripts目录下)
四、可以把之前下载的文件rsa-3.1.1-py2.7.egg拷贝到D:\Python27\Scripts目录下, 然后在cmd中切换到D:\Python27\Scripts目录下,执行egg文件:easy_install.exe rsa-3.1.1-py2.7.egg
加密实例
import os import sys import math def GetDataFromFile(filename): f = open(filename) n = int(f.read(),16) print('*'*77) print(filename) print(hex(n)) print('*'*77) return (n) def my_RSA_encrypt(src, d, n): x = pow(src, d, n) print('*'*77) print("Encrypted Data is:") print(hex(x)) print('*'*77) return x def my_RSA_decrypt(src, e, n): y = pow(src, e, n) print('*'*77) print("Decrypted Data is:") print(hex(y)) print('*'*77) return y path = os.getcwd() #==================================== fname = path + "\\Firm_N.txt" plaintData = GetDataFromFile(fname) fname = path + "\\Manuf_private_d.txt" d = GetDataFromFile(fname) fname = path + "\\Manuf_N.txt" n = GetDataFromFile(fname) encryptedData = my_RSA_encrypt(plaintData, d, n) #==================================== fname = path + "\\Firm_public_e.txt" plaintData = GetDataFromFile(fname) fname = path + "\\Manuf_private_d.txt" d = GetDataFromFile(fname) fname = path + "\\Manuf_N.txt" n = GetDataFromFile(fname) encryptedData = my_RSA_encrypt(plaintData, d, n) #====================================