ImageVerifierCode 换一换
格式:DOCX , 页数:46 ,大小:81.90KB ,
资源ID:16857741      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/16857741.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(现代密码学实验题目+代码Word文档格式.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

现代密码学实验题目+代码Word文档格式.docx

1、 n(26,0); for(int i=0;ix; ) for(int i=0; if(int(x)=si) ni+; float sum=0.0; for(int j=0;j+j) sum+=nj; cout统计结果如下:endl; for(int k=0;k+k) / nk=nk/sum; cout char(k+97)出现的概率为:nk/sum /coutnk (2)仿射变换加/解密程序对一段较长的英文文章进行加密/判断两个数是不是互素(辗转相除)/bool gcd(int a) int f=26,g,r; g=a; do r=f%g; f=g; g=r; while(r); if(f=

2、1) return 1; else return 0;/求逆/int inv(int a) int x,i; for(i=1;=30; if(26*i+1)%a=0) x=(26*i+1)/a;break; return x;/请你选择操作密码的方式:endlz; if(z=0|z=1) /请输入密钥a和b: int a,b;ab; if(a25)|(b25)a,b的输入范围有错! if(gcd(a)=0) cout密钥a有误,与26不互素 else if(z=0)/加密算法 ofstream out(b.txt s.push_back(int(x);s.size(); si=(a*(si-9

3、7)+b)%26; outchar(si+97); outcout加密成功!明文请见“b.txt” else/解密算法 ifstream in( vector si=inv(a)*(si-97-b+26)%26; outvoid main() /下面是密钥的产生/ int a31=1,1,0,0,1; for(int k=5;31;+k) ak=(ak-2+ak-5)%2;密钥如下: for(int jj=0;jj+jj)ajj/ int i=0,key;请选择操作方式: 1-加密 2-解密key; s,ss; if(key=1|key=2) if(key=1) coutc) int sum=

4、0; for(int j=0;8; sum+=pow(2,7-j)*a(i+j)%31; if(i+j32) i=(i+j-1)%31+1; i=i+8; s.push_back(int(c)sum); for(int kk=0;kk+kk) outchar(skk); if(key=2) 解密成功,明文见in.txt /操作无效!四、实验结果及分析在“in.txt”中输入如下内容:实验结果如下:得到密文“out.txt”如下:实验三、流密码(生成非线性序列)以LFSR序列为基础,生成非线性序列,并利用该序列对文件进行加密、解密。1)利用CC+实现Geffe序列生成器及J-K触发器;2)利用生

5、成的非线性序列对文件进行加密、解密(按对应位作模2加运算)。#include /return next stateunsigned char fn_feedback(unsigned char n, unsigned char c, unsigned char curr_state) unsigned char t = c & curr_state; unsigned char s = t & (unsigned char)128;/get first bit for(int i =1; i n; i+) s = s ( (t i) & (unsigned char)128 ); return

6、 (unsigned char)(curr_state (n-1); /return next statevoid lfsr_output_byte(int n, unsigned char c, unsigned char init_state, unsigned char output_bytes, int byte_length) unsigned char next_state = init_state; for(int i = 0; i byte_length; unsigned char temp = (unsigned char)0; j j ); next_state = fn

7、_feedback(n, c, next_state); output_bytesi = temp;/output a char type of data in binary wayvoid output_binary(unsigned char c) if( (c (unsigned char)128 ) cout 1 cout stdio.hwindows.hclass yxyDESpublic: yxyDES(); yxyDES(); void InitializeKey(string); void EncryptData(string); void DecryptData(string

8、 ); void EncryptAnyLength(string); void DecryptAnyLength(string); void SetCiphertext(char* value); char* GetCiphertext(); void SetPlaintext(char* value); char* GetPlaintext(); char* GetCiphertextAnyLength(); char* GetPlaintextAnyLength();private: char SubKeys1648; char szCiphertext16; char szPlainte

9、xt8; char szFCiphertextAnyLength8192; char szFPlaintextAnyLength4096; void CreateSubKey(char*); void FunctionF(char*,char*,int); void InitialPermuteData(string,char*,bool); void ExpansionR(char* ,char*); void XOR(char* ,char* ,int ,char*); string CompressFuncS(char* ); void PermutationP(string ,char

10、*); string FillToEightBits(string); void CleanPlaintextMark(); string HexCharToBinary(char); string HexIntToBinary(int ); string BinaryToString(char*,int,bool); int SingleCharToBinary(char); char SingleBinaryToChar(int);#endif构造主文件:#pragma hdrstop#include yxyDES.h/-#pragma package(smart_init)/ permu

11、ted choice table (PC1)const static int PC1_Table56 = 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4/ permuted choice key (PC2)const

12、static int PC2_Table48 = 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32/ number left rotations of pc1 const static int Shift_Table16 = 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2

13、,1/ initial permutation (IP)const static int IP_Table64 = 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15

14、, 7/ expansion operation matrix (E)static const int E_Table48 = 32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 12, 13, 14, 15, 16, 17, 16, 17, 18, 19, 20, 21, 20, 21, 22, 23, 24, 25, 24, 25, 26, 27, 28, 29, 28, 29, 30, 31, 32, 1/ The (in)famous S-boxes const static int S_Box8416 = / S1 1

15、4, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13, / S2 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7,

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

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