ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

【Python|密码学】仿射加密法实验报告

2021-10-24 09:04:21  阅读:227  来源: 互联网

标签:What 加密 Python v3 v2 does 仿射 密码学


一、实验项目名称(实验题目):
仿射加密法
二、实验目的与要求:
熟悉取模运算、乘法加密、仿射加密,学会元组的使用
三、实验内容:
1、取模运算符%.

>>> 15%12
3
>>> 210%12
6
>>> 10%10
0
>>> 20%10
0
>>> -21%5
4

在这里插入图片描述
2、模逆算法。

def findModInverse(a,m):
    if gcd(a,m) !=1:
        return None #如果a和m不互质,则不存在模逆
    u1,u2,u3=1,0,a
    v1,v2,v3=0,1,m
    while v3 !=0:
        q=u3//v3
        v1,v2,v3,u1,u2,u3=(u1-q*v1),(u2-q*v2),(u3-q*v3),v1,v2,v3
        return u1%m

在这里插入图片描述
在这里插入图片描述
3、运行仿射加密法程序。(15.2节)明文:My name is 。。。。
(加密、解密)
加密
在这里插入图片描述
解密在这里插入图片描述
4、组练习。
1.The affine cipher can be thought of as the combination of which two other ciphers?
2.What is a tuple?
3.How is a tuple different from a list?
4.Why does having Key A be 1 make the affine cipher weak?
5.Why does having Key B be 0 make the affine cipher weak?

1.移位和乘法密码。
2.Python中类似于列表的数据类型,但不可变。
3.元组是不可变的,这意味着它们不能更改其项。
4.因为符号的数字乘以1不会改变它。
5.因为将0添加到符号的编号不会改变它。

5、运行仿射加密法破译程序
在这里插入图片描述
在这里插入图片描述
6、continue 语句。
在这里插入图片描述
7、
View all practice exercises in “Hacking Secret Ciphers with Python”.
1.What does 2 ** 5 evaluate to?
2.What does 6 ** 2 evaluate to?
3.What does the following code print out?

for i in range(5):
    if i == 2:
        continue
    print(i)

在这里插入图片描述
在这里插入图片描述
8、Does the main() function of affineHacker.py get called if another program runs import affineHacker?
NO

标签:What,加密,Python,v3,v2,does,仿射,密码学
来源: https://blog.csdn.net/qq_44762986/article/details/120899789

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有