·
1
·
云南大学数学与统计学院
上机实践报告
近代密码学实验
级
陆正福
刘鹏
古典加密技术实验
No.02
08:32
一、 实验目的
熟悉古典密码学的思路和方法。
二、 实验内容
1. 编程实现古典密码学的主要体制和算法
2. 编程实现古典密码学的主要分析方法。
三、 实验平台
Windows 10 1703 Enterprise(Edit Reports);
SageMath version 8.1, Release Date: 2017-12-07;
Ubuntu 17.10 x86-64;
Xshell 5 Build 1339。
四、 实验记录与实验结果分析
4.1 题
在 SageMath 下,编程实现以 Caesar 加密为代表的古典加密方法(对字母表进行变换)。参考 P.501
B.1 第 2 章:传统加密技术
[1]
。
Solution:
4.1.1 程序代码
2
3
4
5
6
7
8
9
10
11
# in the English alphabet
#
def num_to_char(x):
return en_alphabet[x % 26]
def CaesarEncrypt(k, plaintext):
ciphertext = ""
for j in xrange(len(plaintext)):
p = plaintext[j]
if is_alphabetic_char(p):
x = (k + char_to_num(p)) % 26
评论0