下载此文档

密码学上机实验二报告(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)

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

非法内容举报中心
文档信息
  • 页数11
  • 收藏数0 收藏
  • 顶次数0
  • 上传人乘风破浪
  • 文件大小45 KB
  • 时间2019-03-19