#!python2
import argparse
from Crypto.PublicKey import RSA
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-f',' infile', help="input a .pem file which contains pubilc key")
group.add_argument('-ne',nargs=2, help="value of n and e")
args = parser.parse_args()
# - Here we search for n and e -
if args.infile:
PublicKey = args.infile
OpenPublicKey = open(PublicKey, 'r')
ReadPublicKey = OpenPublicKey.read()
TheKey = RSA.importKey(ReadPublicKey)
n = long(TheKey.n)
e = long(TheKey.e)
else:
n,e=map(long,args.ne)
print 'This is modulus n: ', n
print 'This is public exponent e: ', e
对于文件输入:
^{pr2}$对于变量输入:
只需为
-n
和-e
添加可选关键字参数如果
args.n and args.e
的计算结果为True
,则忽略输入参数并跳过处理它的代码。在相关问题 更多 >
编程相关推荐