实验报告1
课程名称
网络信息安全技术
任课教师
 
朱云初
   
 
软件学院
   
软件工程
一、 实验名称:
实验一、破译vigenère 密码加密的密文
二、 实验目的:
熟悉vigenère 密码加密及解密方法
三、实验内容及要求
密钥长度3~16
明文为普通英文文章(仅含小写字母);
实现vigenère 加密、解密;
破译密文
提交的报告:
选择的密钥、明文、加密后的密文;
破译密文的过程;
分析使用、破译vigenère密码时应当考虑的所有因素。
四、实验材料、工具、或软件
普通计算机一台,并安装Java AppletIEDreamweaverMX2004等软件
五、实验步骤(或记录)
1、选择的密钥、明文、加密后的密文
密钥为:Computer
明文为:
My name is Zhu Yun beginning of the South China University of Technology Software Engineering, Zhaoqing, the students, the first phase of the new school curriculum is called network information security technology, classroom teacher is Feng Yuxiang.
加密后的密文:
Om cufi kg Obn Pwb qyzmepwzv hj vvq Mhykj Owcge Wbukykwzvm dz Xvevzdfhkp Gaunpeig Qcabrvgfuca, Qjoafcgk, htt lxlfszim, kjs uckwk dtpmx fh fwy rvy erbhsc qgglbglniy cl tczxtx rvvkage mehcdbummfp etwnvzvm iyvleqzavs, tnoehlhsd hqpwaii we Zxrx Mgmctrx.
2、破译过程
按照vigenère 密码技术编写网页文件,代码以下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gbk" /> 
<meta http-equiv="Page-Enter" content="revealTrans(Duration=2,Transition=23)"> 
<meta http-equiv="Page-Exit" content="revealTrans(Duration=2,Transition=23)"> 
<title>维吉尼亚(Vigenère)密码 </title> 
<style> 
    body{ 
        font-size:18px; 
        font-family:"楷体_GB2312", "仿宋_GB2312"; 
    } 
    caption{ 
        text-align:center; 
        font-size:20px; 
        font-weight:bold;     
    } 
    center{ 
        font-size:28px; 
        font-weight:bold;     
    } 
    .matrix{ 
        border:#BBBBFF solid thick; 
        cursor:pointer; 
    } 
    .matrix td{ 
        width:18px; 
        height:18px;     
        border:#aaccaa 1px solid; 
        text-align:center; 
    } 
    .matrix th{ 
        width:18px; 
        height:18px; 
        border:#DDDDFF 1px solid; 
        background-color:#EEEEFF; 
        text-align:center; 
    } 
    .cal{ 
        padding:20px 20px 20px 20px; 
    } 
    .cal td,th{ 
        border-width:0px; 
    } 
</style> 
</head> 
<script language="javascript"> 
    //-----------声明全局变量-------------- 
    var AU="A".charCodeAt(0);//大写A的编码 
    var AL="a".charCodeAt(0);//小写a的编码 
    var ZU="Z".charCodeAt(0);//大写Z的编码 
    var ZL="z".charCodeAt(0);//小写z字符串长度计算工具的编码 
    var col1,col2;//方阵的列 
    //--------------方阵函数--------- 
    function writeThead(){//方阵表头部 
        document.writeln("<thead><tr><th> </th>"); 
        for(var i=0;i<26;i++){ 
            document.writeln("<th>"+String.fromCharCode(AU+i)+"</th>"); 
        } 
        document.writeln("</tr></thead>"); 
    } 
    function forTo(i,j){//向前映射 
        return (i+j)%26; 
    } 
    function backTo(i,j){//向后映射 
        return (i+26-j)%26; 
    } 
    function writeTbody(fun,id){//方阵体,传入映射函数和表编号 
        //document.writeln("<colgroup span='26'>"); 
            for(var i=0;i<=26;i++){ 
                document.writeln("<col/>"); 
            } 
        //document.writeln("</colgroup>"); 
        document.writeln("<tbody>"); 
        for(var i=0;i<26;i++){ 
            document.writeln("<tr onmouseover='this.style.backgroundColor=\"#DDDDff\"' onmouseout='this.style.backgroundColor=\"\"'>"); 
            document.writeln("<th>"+String.fromCharCode(AU+i)+"</th>"); 
            for(var j=0;j<26;j++){ 
                document.writeln("<td onmouseover='pointIn("+j+",col"+id+")' onmouseout='pointOut("+j+",col"+id+")'>"+String.fromCharCode(AU+fun(i,j))+"</td>"); 
            } 
            document.writeln("</tr>");     
        } 
        document.writeln("</tbody>"); 
    } 
    function initCols(){//初始化列向量 
        ElementById("matrix1").getElementsByTagName("col"); 
        ElementById("matrix2").getElementsByTagName("col"); 
    } 
    function pointIn(j,cols){//鼠标处于j列时修改此列颜 
        cols[j+1].style.backgroundColor="#DDDDFF"; 
    } 
    function pointOut(j,cols){//鼠标移出j列时恢复此列颜 
        cols[j+1].style.backgroundColor=""; 
    } 
    //------------------加密解密函数----------- 
    function isUpLetter(c){//判断是否为大写字符编码 
        if(c>=AU&&c<=ZU)return true; 
        else return false; 
    } 
    function isLowLetter(c){//判断是否为小写字符编码 
        if(c>=AL&&c<=ZL)return true; 
        else return false; 
    } 
    function isLetter(c){//判断是否为英文字符编码 
        return isUpLetter(c)||isLowLetter(c); 
    } 
    function isLetterStr(s){//判断是否为英文字符串 
        for(var i=0;i<s.length;i++){ 
            if(!isLetter(s.charCodeAt(i))) 
                return false; 
        } 
        return true; 
    } 
    function jiami(){//加密函数 
        var key=document.form1.LowerCase(); 
        if(!isLetterStr(key)){ 
            alert("密钥必须为全英文字符串!"); 
            document.form1.miyao.focus(); 
            return false; 
        } 
        var express= document.form1.mingwen.value; 
        var secret=""; 
        if(key.length==0)secret=express; 
        else{ 
            var A; 
            var ee; 
            for(var i=0;i<express.length;i++){ 
                ee=express.charCodeAt(i); 
                if(isUpLetter(ee))A=AU; 
                else if(isLowLetter(ee))A=AL; 
                else{ 
                    secret+=express.charAt(i); 
                    continue; 
                } 
                secret+=String.fromCharCode(A+((ee-A)+(key.charCodeAt(i%key.length))-AL)%26); 
            } 
        } 
        document.form1.miwen.value=secret; 
    } 
    function jiemi(){//解密函数 
        var key=document.form1.LowerCase(); 
        if(!isLetterStr(key)){ 
            alert("密钥必须为全英文字符串!"); 
            document.form1.miyao.focus(); 
            return false; 
        } 
        var secret= document.form1.miwen.value; 
        var express=""; 
        if(key.length==0)express=secret; 
        else{ 
            var A; 
            var se; 
            for(var i=0;i<secret.length;i++){ 
                se=secret.charCodeAt(i); 
                if(isUpLetter(se))A=AU; 
                else if(isLowLetter(se))A=AL; 
                else{ 
                    express+=secret.charAt(i); 
                    continue; 
                } 
                express+=String.fromCharCode(A+((se-A)+26-(key.charCodeAt(i%key.length)-AL))%26); 
            } 
        } 
        document.form1.mingwen.value=express; 
    } 
</script> 
<body onload="initCols()"> 
    <center>网络信息安全技术课程破译vigenère密码加密的密文作业</center>     
    <form name="form1">         
        <table class="cal" width="70%" border="5" align="center" cellpadding="0" cellspacing="0"> 
            <caption></caption> <tr> 
                <td colspan="3" align="center">密钥: <input name="miyao" type="text" size="100" value=""/></td></tr><tr><td width="0%">明文: <br/>         
              <textarea name="mingwen" cols="50" rows="10"></textarea></td>         
                <td width="0%"> 
                  <input name="button" type="button" value="加密>>" onclick="jiami()" /><br/> 
                    <input type="button" name="Submit2" value="<<解密" onclick="jiemi()" /></td> 
                <td width="0%">密文:<br/><textarea name="miwen" cols="50" rows="10"></textarea></td>         
            </tr></table></form><br/> 
    <table border="0" align="center"><tr><td> 
            <table id="matrix1" class="matrix" cellpadding="0" cellspacing="0" align="center"> 
                <caption> 
                    加密方阵<br/> 
                    密钥(行/列)+明文(列/行)=密文   
                </caption> 
                <script language="javascript"> 
                    writeThead(); 
                    writeTbody(forTo,1); 
                </script> 
            </table></td><td> 
            <table id="matrix2" class="matrix" cellpadding="0" cellspacing="0" align="center"> 
                <caption>解密方阵<br/> 
                    密文(行)-密钥(列)=明文   
                </caption> 
                <script language="javascript"> 
                    writeThead(); 
                    writeTbody(backTo,2); 
                </script> 
            </table></td></tr></table> 
</body></html>
以上代码通过IE运行,显示界面如下图:
2、破译过程
要确定密钥,即确定k1 , k2 , k3 , k4 , k5 的值, 可以再一次使用指数重合法。的每个子串Yi 是相应的明文xi 移动ki 个位置得到的,明文中A B . . . Z 出现的概率.Ki可能取值为0-25,逐一代入得出密钥:computer
通过加密方阵及解密方阵进行对比,在明文框或密文框内输入即可相互得到结果。
如果破译更长的密码,在程序中修改相关的数据即可。明文输入可以是普通文章且带标点符号,程序可以过滤非法字符。
六、实验存在问题和解决办法
七、意见和建议
八、教师评语(或成绩)
                                                      教师签字:   
                                                           
实验报告2

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。