python写接口自动化需要rsa加密_RSA加密,请问如何用Python实现该加密过程
展开全部
^import random
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
def multiplicative_inverse(e, phi):
d = 0
x1 = 0
x2 = 1
y1 = 1
temp_phi = phi
while e > 0:
temp1 = temp_phi/e
temp2 = temp_phi - temp1 * e
temp_phi = e
e = temp2
x = x2- temp1* x1
y = d - temp1 * y1
x2 = x1
x1 = x
d = y1
y1 = y
if temp_phi == 1:
return d + phi
'''
Tests to see if a number is prime.
'''
def is_prime(num):
if num == 2:
return True
if num
return False
for n in xrange(3, int(num**0.5)+2, 2):
if num % n == 0:
return False
return True
def generate_keypair(p, q):
if not (is_prime(p) and is_prime(q)):
raise ValueError('Both numbers must be prime.')
elif p == q:
raise ValueError('p and q cannot be equal')
#n = pq
n = p * q
#Phi is the totient of n
phi = (p-1) * (q-1)
#Choose an integer e such that e and phi(n) are coprime
e = random.randrange(1, phi)
#Use Euclid's Algorithm to verify that e and phi(n) are comprime
g = gcd(e, phi)
while g != 1:
e = random.randrange(1, phi)
g = gcd(e, phi)
#Use Extended Euclid's Algorithm to generate the private key
d = multiplicative_inverse(e, phi)
#Return public and private keypair
#Public key is (e, n) and private key is (d, n)
return ((e, n), (d, n))
def encrypt(pk, plaintext):
#Unpack the key into it's components
key, n = pk
#Convert each letter in the plaintext to numbers based on the character using a^32313133353236313431303231363533e78988e69d8331333363353866b mod m
cipher = [(ord(char) ** key) % n for char in plaintext]
#Return the array of bytes
return cipher
def decrypt(pk, ciphertext):
#Unpack the key into its components
key, n = pk
#Generate the plaintext based on the ciphertext and key using a^b mod m
plain = [chr((char ** key) % n) for char in ciphertext]
#Return the array of bytes as a string
return ''.join(plain)
if __name__ == '__main__':
print "RSA Encrypter/ Decrypter"
p = int(raw_input("Enter a prime number (17, 19, 23, etc): "))
q = int(raw_input("Enter another prime number (Not one you entered above): "))
print "Generating your public/private keypairs now . . ."
public, private = generate_keypair(p, q)
print "Your public key is ", public ," and your private key is ", private
message = raw_input("Enter a message to encrypt with your private key: ")
encrypted_msg = encrypt(private, message)
print "Your encrypted message is: "
print ''.join(map(lambda x: str(x), encrypted_msg))
print "Decrypting message with public key ", public ," . . ."
print "Your message is:"
print decrypt(public, encrypted_msg)
python写接口自动化需要rsa加密_RSA加密,请问如何用Python实现该加密过程相关推荐
- python 基于unittest写接口自动化脚本
已过时.如感兴趣,请移步这篇文章 https://blog.csdn.net/tomoya_chen/article/details/121550706 python 基于unittest写接口自动化 ...
- python+pytest接口自动化之测试函数、测试类/测试方法的封装
前言 今天呢,笔者想和大家聊聊python+pytest接口自动化中将代码进行封装,只有将测试代码进行封装,才能被测试框架识别执行. 例如单个接口的请求代码如下: import requestshea ...
- python写一个接口_如何用python写接口
如何用python写接口?具体步骤如下: 1.实例化server 2.装饰器下面的函数变为一个接口 3.启动服务 开发工具和流程: python库:flask =>实例化server:serve ...
- Python UnitTest接口自动化实战
目录 一.需注意事项 二.单元测试框架unittest 2.1 作用 2.2 测试用例(TestCase) 2.2.1 单元测试函数 2.2.2 测试函数的执行顺序 2.3 用例收集器(TestLoa ...
- python做接口自动化测试仪器经销商_Python接口自动化测试的实现
接口测试的方式有很多,比如可以用工具(jmeter,postman)之类,也可以自己写代码进行接口测试,工具的使用相对来说都比较简单,重点是要搞清楚项目接口的协议是什么,然后有针对性的进行选择,甚至当 ...
- 【接口自动化】3.写接口自动化case要注意的点
可能有人会说,写接口的自动化CASE多简单了,写个参数发送请求完事了,还要注意啥? 没错,相比起UI自动化的case,你要去写各种定位器,接口自动化的case写起来确实容易多了.这也是接口自动化 的一 ...
- 跳槽涨薪技术之python+pytest接口自动化(6)-请求参数格式的确定
[文章末尾给大家留下了大量的福利] 我们在做接口测试之前,先需要根据接口文档或抓包接口数据,搞清楚被测接口的详细内容,其中就包含请求参数的编码格式,从而使用对应的参数格式发送请求.例如某个接口规定的请 ...
- python实现接口自动化
一.总述 Postman:功能强大,界面好看响应格式自主选择,缺点支持的协议单一且不能数据分离,比较麻烦的还有不是所有的公司都能上谷歌 SoupUI:支持多协议(http\soup\rest等),能实 ...
- 浅谈python+requests接口自动化框架
为什么要做接口自动化框架 1.业务与配置的分离 2.数据与程序的分离:数据的变更不影响程序 3.有日志功能,实现无人值守 4.自动发送测试报告 5.不懂编程的测试人员也可以进行测试 正常接口测试的流程 ...
最新文章
- github删除文件夹
- 数据可视化教程来了!
- 实现php实现价格的排序,PHP实现二维数组排序(按照数组中的某个字段)
- 世界上没有后悔药,时间匆匆,从关注它们开始......
- Java8系列之重新认识HashMap
- java计算整数出现的次数_[剑指offer题解][Java]1到n整数中1出现的次数
- QuickPart应用系列
- 一篇文章看清楚JDK13的特性!
- Reactor模式 NIO epoll
- 富文本编辑器内容存储至Mysql
- 机器学习模型评价指标(准确率、精度、召回率)
- java 注解 mapping_@RequestMapping注解详解
- 您的Android版本不兼容,android – “你的设备与此版本不兼容”
- 让你的微信小程序对用户更加友好:上拉加载和下拉刷新就是关键
- 岸上的猫和水里的老鼠
- 基于B/S模式的设备管理系统开发
- 如何修改第三方DLL文件名
- USB class总结
- oracle中ln函数,PLSQL LN用法及代码示例
- 趣店被骂只是开始,一大批消费金融公司正在走向“危险地带”
热门文章
- C语言编译报错:incompatible pointer type [-Wincompatible-pointer-types](传参类型不匹配)
- python matplotlib pyplot plt.axhline()函数(绘制平行于x轴的水平参考线)
- SpringBoot 使用WebMvcConfigurer处理请求
- Kafka工作原理简要概述
- arcgis飞行轨迹动画_高德地图,百度地图,arcgis地图利用canvas动画绘制圆形扩散、运动轨迹等动态效果...
- 小麦盒子cdn_阿里云CDN入门使用配置
- 郑州学python_郑州Python基础知识点学习之内置类型
- java中IO流用到了哪种设计模式
- 多元经验模态分解_环境激励桥梁模态参数识别—环境激励模态参数识别概述
- MYSQL中的主表和父表_主表,从表,关联表,父表,子表