优质密码实验报告2 800字精选word文档 13页Word格式.docx

上传人:b****6 文档编号:16365767 上传时间:2022-11-23 格式:DOCX 页数:10 大小:17.47KB
下载 相关 举报
优质密码实验报告2 800字精选word文档 13页Word格式.docx_第1页
第1页 / 共10页
优质密码实验报告2 800字精选word文档 13页Word格式.docx_第2页
第2页 / 共10页
优质密码实验报告2 800字精选word文档 13页Word格式.docx_第3页
第3页 / 共10页
优质密码实验报告2 800字精选word文档 13页Word格式.docx_第4页
第4页 / 共10页
优质密码实验报告2 800字精选word文档 13页Word格式.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

优质密码实验报告2 800字精选word文档 13页Word格式.docx

《优质密码实验报告2 800字精选word文档 13页Word格式.docx》由会员分享,可在线阅读,更多相关《优质密码实验报告2 800字精选word文档 13页Word格式.docx(10页珍藏版)》请在冰豆网上搜索。

优质密码实验报告2 800字精选word文档 13页Word格式.docx

1.通过预习和老师在实验课上的讲解,理解代替密码和移位密码的本质差别,对程序的作用有初步了解;

2.分析实验指导书上所列代码,搞清楚各个子函数的功能、理清程序的大体思路;

3.将主函数与各个子函数进行合并整合,处理编译上出现的语法问题,使编译可以顺利通过;

4.完善程序,输入数据对程序的逻辑功能进行验证,测试随机数结构调用是否完整,测试结果是否符合对应的加密要求,验证打开关闭文件是否顺利。

六、思考题

“代替表”与“置换”的不动点、逆等是否一致?

答:

不一致。

代替是约定明文集合到另一集合的关系,不一定是原来的集合,而移位是在明文集合中进行随机排列然后得到的密文。

两者的不动点、逆等只有在统一集合变换时才可能一致。

七、实验代码及运行结果

实验代码:

1.代替密码

#include<

stdio.h>

time.h>

string.h>

ctype.h>

stdlib.h>

/*声明子函数*/

unsignedchar*full_array2(charn);

/*fully_array函数产生随机数*/intletter_to_digit(charc);

chardigit_to_letter(intn);

unsignedchar*KeyGen_s();

voidEncrypt_s(unsignedchar*key);

/*主函数*/

intmain()

{

printf("

---------代替密码加密算法---------\n"

);

Encrypt_s(KeyGen_s());

system("

pause"

return0;

}

unsignedchar*full_array2(charn)/*fully_array函数产生随机数*/{

intm,i,j,k,l=0,flag;

staticunsignedcharP[256];

start:

\n请输入不小于%d的所有随机数个数:

\n"

n+1);

scanf("

%d"

&

m);

if(m<

=n)

\n输入数%d比%d小,须重新输入!

m,n+1);

gotostart;

srand((unsigned)time(NULL));

/*初始化随机种子*/

for(i=0;

i<

m;

i++)

P[l++]=(unsignedchar)(rand()%(n+1));

for(j=0;

j<

l-1;

j++)

if(P[j]==P[l-1])

l--;

break;

k=l;

=n;

flag=0;

k;

if(P[j]==i)

flag=l;

if(!

flag)

P[l]=i;

l++;

return(P);

intletter_to_digit(charc)

inti;

charalphabet[27]={"

abcdefghijklmnopqrstuvwxyz"

};

for(i=0;

26;

i++)if(tolower(c)==alphabet[i])return(i);

return(-1);

chardigit_to_letter(intn)

if(n<

0||n>

25)return(0);

return(alphabet[n]);

unsignedchar*KeyGen_s()

charKeyWords[106];

charChoiceWords[26];

unsignedchar*p;

staticunsignedcharKeyTab[26*3];

inti,j,k,l;

\n请输入密钥字:

gets(KeyWords);

strcat(KeyWords,"

k=0;

l=strlen(KeyWords);

ChoiceWords[k]=tolower(KeyWords[0]);

for(i=1;

l;

if(letter_to_digit(KeyWords[i])==-1)continue;

ChoiceWords[++k]=tolower(KeyWords[i]);

for(j=0;

if(ChoiceWords[j]==ChoiceWords[k])

k--;

KeyTab[i]=(unsignedchar)letter_to_digit(ChoiceWords[i]);

p=full_array2(25);

KeyTab[26+i]=p[i];

KeyTab[52+i]=(unsignedchar)((7*i+3)%26);

return(KeyTab);

voidEncrypt_s(unsignedchar*key)

FILE*fp;

charfilename[20],c;

\n请输入待加密文本文件名:

%s"

filename);

if((fp=fopen(filename,"

rt"

))==NULL)

没有找到文件:

%s\n"

\n密文如下:

i=0;

while((c=fgetc(fp))!

=EOF)

if(letter_to_digit(c)==-1)

putchar(c);

continue;

//公式选为7*i+3(mod26)

isupper(c)?

putchar(toupper(digit_to_letter(key[(int)((i/26)*26+letter_to_digit(c))]))):

\

putchar(digit_to_letter(key[(int)((i/26)*26+letter_to_digit(c))]));

i++;

if(i>

=26*3)i=0;

fclose(fp);

2.移位密码

intletter_to_digit(charc);

chardigit_to_letter(charn);

unsignedchar*KeyGen_p();

voidEncrypt_p(unsignedchar*key);

---------移位密码加密算法---------\n"

Encrypt_p(KeyGen_p());

(周期为5)\n"

scanf("

intletter_to_digit(charc)/*将字母转化为数字*/

chardigit_to_letter(charn)/*将数字转化为字母*/

unsignedchar*KeyGen_p()/*产生密钥*/

staticunsignedcharKeyTab[16*5];

inti,j;

5;

p=full_array2(15);

16;

KeyTab[16*i+j]=p[j];

voidEncrypt_p(unsignedchar*key)/*实现明文加密*/

chard[16];

gotostart;

}

d[i%16]=c;

i++;

if(i%16!

=0)continue;

putchar(d[key[(int)(((i-1)/16)*16+j)]]);

if(i>

=16*5)i=0;

=0)

for(j=i%16;

j++)d[j]='

*'

;

putchar(d[key[(int)((i/16)*16+j)]]);

putchar('

\n'

附录:

运行结果截图

∙荐计算机上机实验内容及实验报告要求

∙荐构建学校德育管理与评价体系的实验报告

∙荐化学实验报告格式

∙荐大学物理实验课程设计实验报告

∙荐电路实验报告要求

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1