下载此文档

密码学上机实验二报告(Matlab).doc


文档分类:高等教育 | 页数:约11页 举报非法文档有奖
1/11
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/11 下载此文档
文档列表 文档介绍
Forpersonaluseonlyinstudyandresearch;:00-21:00羂实验楼102薁指导教师:候书会芀实验名称:芅1、上机实验二蚄实验内容:荿实验四现代对称密码学实验(验证性实验,4学时)莀AES蚅 A、实验内容:熟悉AES算法,并实现AES;膂 B、测试数据:任意,并验证加/:肆程序代码如下所示:袄膁functionplaintext=inv_cipher(ciphertext,w,inv_s_box,inv_poly_mat,vargin)薀蒇ifnargin>0节袀%Switchtheverbosemodeflagon虿verbose_mode=1;袈肄%Ifthereisnooptional"verbosemode"argument羃else蝿肅%Switchtheverbosemodeflagoff螆verbose_mode=0;蚂蝿end蒆膄%Iftheinputvectorisacellarrayordoesnothave16elements蒁ifiscell(ciphertext)|prod(size(ciphertext))~=16衿袇%Informuserandabort袆error('Ciphertexthastobeavector(notacellarray)with16elements.')芀罿end芈莃%Ifanyelementoftheinputvectorcannotberepresentedby8bits节ifany(ciphertext<0|ciphertext>255)聿莄%Informuserandabort肅error('Elementsofciphertextvectorhavetobebytes(0<=ciphertext(i)<=255).')肁腿end螅薃%Iftheexpandedkeyarrayisacellarrrayordoesnothavethecorrectsize螀ifiscell(w)|any(size(w)~=[44,4])艿膆%Informuserandabort芅error('whastobeanarray(notacellarray)with[44x4]elements.')袃莈end薇蚃ifany(w<0|w>255)薂莈%Informuserandabort羈error('Elementsofkeyarraywhavetobebytes(0<=w(i,j)<=255).')蒅莁end蒈肅state=reshape(ciphertext,4,4);袃膀%Displayintermediateresultifrequested薈ifverbose_mode蒆disp_hex('Initialstate:',state)薅end膃蚈round_key=(w(41:44,:))';袇肂%Displayintermediateresultifrequested羁ifverbose_mode螈disp_hex('Initialroundkey:',round_key)芇end螄螀%Add(xor)thecurrentroundkey(matrix)tothestate(matrix)袈state=add_round_key(state,round_key);蚈膂%Loopover9roundsbackwards螃fori_round=9:-1:1袈袅%Displayintermediateresultifrequested羄ifverbose_mode薂disp_hex(['Stateatstartofround',num2str(i_round),':'],state)羇end芆蚆%Cyclicallyshiftthelastthreerowsofthestatematrix芁state=inv_shift_rows(state);肇蚇%Displayintermediateresultifrequested肄ifverbose_mode肀disp_hex('Afterinv_shift_rows:',state)膇end肈state=sub_bytes(state,inv_s_box);袆肃%Displayintermediateresultifrequested芇ifverbose_mode膅disp_hex('Afterinv_sub_bytes:',state)芄end袂莇%Extractthecurrentroundkey(4x4matrix)fr

密码学上机实验二报告(Matlab) 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数11
  • 收藏数0 收藏
  • 顶次数0
  • 上传人雾里看花
  • 文件大小45 KB
  • 时间2019-05-06