古典密码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验1: 古典密码
一、实验名称和性质
二、实验目的
掌握古典密码体制中的基本加密解密运算,如加法密码、仿射密码等,几种典型的古典密码体制,如Hill体制,以及关于这些古典密码体制的一些破译方法。
三、实验的软硬件环境要求
硬件环境要求:
单机,无需上Internet网。
使用的软件名称、版本号以及模块:
使用Matlab,版本6.0或以上。
四、知识准备
前期要求掌握的知识:
Matlab编程
实验相关理论或原理:
古典密码的基本加密解密运算,几种典型古典密码的加密解密算法。
实验流程:
五、实验要求和注意事项
1.完成给出的程序中标有“-----------------------”部分的编程。
2.参照例子的做法,完成实验题目。要求给出完整的过程,包括程序,实验结果。
六、实验步骤和内容
1.基本的加密解密运算
例1. 使用加法密码(或称为移位密码)获得密文kddkmu,尝试所有的可能性来解密它。解:编写allshift程序,调用该程序
allshift('kddkmu')
运行结果为
kddkmu
leelnv
mffmow
nggnpx
ohhoqy
piiprz
qjjqsa
rkkrtb
sllsuc
tmmtvd
unnuwe
voovxf
wppwyg
xqqxzh
yrryai
zsszbj
attack 是列表上出现的唯一单词,所以它就是明文buubdl
cvvcem
dwwdfn
exxego
fyyfhp
gzzgiq
haahjr
ibbiks
jccjlt
function y = allshift(x);
% This function displays all of the shifts of the message x
for j=0:25,
------------ ;
disp(z);
end
function y = shift(x,b);
% This function performs the shift encryption function
% y = x + b mod 26
% We assume that x is a text string and b is a number
% The result is kept in text representation
xnum=text2int(x);
-----------------------;
y=int2text(ynum);
function y = text2int (x)
% This function takes the letter in the string x and converts
% it to an integer.
% The convention for this function is
% a --> 0
% b --> 1
% and so on...
if ( (x < 'a') | (x > 'z') ),
error('Text character out of range a-z');
end;
y=x - 'a'; %It helps to know Matlab tricks
function y = int2text (x)
% This function takes the number in the variable x and converts
% it to a character y.
% The convention for this function is
% a <-- 0
% b <-- 1
% and so on...
if ( (x < 0) | (x > 25) ),
error('Integer out of range 0 - 26');
end;
y=char(x + 'a'); %It helps to know Matlab tricks
例2. 运用仿射函数7x +8 加密明文信息cleopatra 。
解:编写affinecrypt 程序,调用该程序,得
affinecrypt('cleopatra',7,8)
ans =
whkcjilxi
function y = affinecrypt(x,a,b);
% This function performs the affine encryption function
% y = a x + b mod 26
% where (a,26) = 1
% The result is kept in numerical representation
--------------------------------
2.典型的古典密码体制
例3. 密文
22, 09, 00, 12, 03, 01, 10, 03, 04, 08, 01, 17
是使用如下的Hill 密码加密的:
1234567810⎛⎫ ⎪ ⎪ ⎪⎝⎭
试破解它。
解:
首先将加密矩阵放入变量K 。
>> K=[1 2 3;4 5 6;7 8 10]