版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、单表查询:#include <stdio.h>#include <iostream>char M100;char C100;void jiami();void jiemi();void main()int choice;printf("加密请输入数字1,解密请输入数字2,退出请输入其他键:n"); scanf("%d",&choice); if(choice=1)jiami();if(choice=2)jiemi();void jiami() int K,i; fflush(stdin); printf("请输入
2、明文:n",M); gets(M); printf("请输入K值:"); scanf("%d",&K); for(i=0;Mi!='0'i+) if(Mi>='a'&&Mi<='z') Ci=(Mi-'a'+K)%26+'a' else if(Mi>='A'&&Mi<='Z') Ci=(Mi-'A'+K)%26+'A' else Ci=
3、39; 'Ci='0'printf("密文是:n%sn",C); void jiemi() int K,i; fflush(stdin); printf("请输入密文:n"); gets(C); printf("请输入K值:"); scanf("%d",&K); for(i=0;Ci!='0'i+) if(Ci>='a'&&Ci<='z') Mi=(Ci-'a'-K)%26+'a
4、9; else if(Ci>='A'&&Ci<='Z') Mi=(Ci-'A'-K)%26+'A' else Mi=' 'Mi='0'printf("明文是:n%sn",M);移位寄存器#include"stdio.h"#include"stdlib.h"#define N 3 int i=3; int n=10; double RN; Input(); GF(); int main()Input();GF();
5、return 0;Input()printf("Please input R:n",R);for(i=1;i<=N;i+) scanf("%d",&Ri);return 0;GF()int f;int i=1;while(n) f=(int)(Ri*Ri+1+Ri+2)%2; Ri=Ri+1;Ri+1=Ri+2;Ri+2=f; printf("%d ",Ri);n-;i+;return 0;IDEA#include "idea.h"#include "idea_lcl.h"void
6、 idea_cbc_encrypt(in, out, length, ks, iv, encrypt)unsigned char *in;unsigned char *out;long length;IDEA_KEY_SCHEDULE *ks;unsigned char *iv;int encrypt;register unsigned long tin0,tin1;register unsigned long tout0,tout1,xor0,xor1;register long l=length;unsigned long tin2;if (encrypt)n2l(iv,tout0);n2
7、l(iv,tout1);iv-=8;for (l-=8; l>=0; l-=8)n2l(in,tin0);n2l(in,tin1);tin0=tout0;tin1=tout1;tin0=tin0;tin1=tin1;idea_encrypt(tin,ks);tout0=tin0; l2n(tout0,out);tout1=tin1; l2n(tout1,out);if (l != -8)n2ln(in,tin0,tin1,l+8);tin0=tout0;tin1=tout1;tin0=tin0;tin1=tin1;idea_encrypt(tin,ks);tout0=tin0; l2n(
8、tout0,out);tout1=tin1; l2n(tout1,out);l2n(tout0,iv);l2n(tout1,iv);elsen2l(iv,xor0);n2l(iv,xor1);iv-=8;for (l-=8; l>=0; l-=8)n2l(in,tin0); tin0=tin0;n2l(in,tin1); tin1=tin1;idea_encrypt(tin,ks);tout0=tin0xor0;tout1=tin1xor1;l2n(tout0,out);l2n(tout1,out);xor0=tin0;xor1=tin1;if (l != -8)n2l(in,tin0)
9、; tin0=tin0;n2l(in,tin1); tin1=tin1;idea_encrypt(tin,ks);tout0=tin0xor0;tout1=tin1xor1;l2nn(tout0,tout1,out,l+8);xor0=tin0;xor1=tin1;l2n(xor0,iv);l2n(xor1,iv);tin0=tin1=tout0=tout1=xor0=xor1=0;tin0=tin1=0;void idea_encrypt(d,key)unsigned long *d;IDEA_KEY_SCHEDULE *key;register IDEA_INT *p;register u
10、nsigned long x1,x2,x3,x4,t0,t1,ul;x2=d0;x1=(x2>>16);x4=d1;x3=(x4>>16);p= &(key->data00);E_IDEA(0);E_IDEA(1);E_IDEA(2);E_IDEA(3);E_IDEA(4);E_IDEA(5);E_IDEA(6);E_IDEA(7);x1&=0xffff;idea_mul(x1,x1,*p,ul); p+;t0= x3+ *(p+);t1= x2+ *(p+);x4&=0xffff;idea_mul(x4,x4,*p,ul);d0=(t0&
11、amp;0xffff)|(x1&0xffff)<<16);d1=(x4&0xffff)|(t1&0xffff)<<16);/* The input and output encrypted as though 64bit cfb mode is being * used. The extra state information to record how much of the * 64bit block we have used is contained in *num; */void idea_cfb64_encrypt(in, out, l
12、ength, schedule, ivec, num, encrypt)unsigned char *in;unsigned char *out;long length;IDEA_KEY_SCHEDULE *schedule;unsigned char *ivec;int *num;int encrypt;register unsigned long v0,v1,t;register int n= *num;register long l=length;unsigned long ti2;unsigned char *iv,c,cc;iv=(unsigned char *)ivec;if (e
13、ncrypt)while (l-)if (n = 0)n2l(iv,v0); ti0=v0;n2l(iv,v1); ti1=v1;idea_encrypt(unsigned long *)ti,schedule);iv=(unsigned char *)ivec;t=ti0; l2n(t,iv);t=ti1; l2n(t,iv);iv=(unsigned char *)ivec;c= *(in+)ivn;*(out+)=c;ivn=c;n=(n+1)&0x07;elsewhile (l-)if (n = 0)n2l(iv,v0); ti0=v0;n2l(iv,v1); ti1=v1;i
14、dea_encrypt(unsigned long *)ti,schedule);iv=(unsigned char *)ivec;t=ti0; l2n(t,iv);t=ti1; l2n(t,iv);iv=(unsigned char *)ivec;cc= *(in+);c=ivn;ivn=cc;*(out+)=ccc;n=(n+1)&0x07;v0=v1=ti0=ti1=t=c=cc=0;*num=n;char *IDEA_version="IDEA part of OpenSSL 0.9.1c 23-Dec-1998"char *idea_options()if
15、 (sizeof(short) != sizeof(IDEA_INT)return("idea(int)");elsereturn("idea(short)");void idea_ecb_encrypt(in, out, ks)unsigned char *in;unsigned char *out;IDEA_KEY_SCHEDULE *ks;unsigned long l0,l1,d2;n2l(in,l0); d0=l0;n2l(in,l1); d1=l1;idea_encrypt(d,ks);l0=d0; l2n(l0,out);l1=d1; l2
16、n(l1,out);l0=l1=d0=d1=0;/* The input and output encrypted as though 64bit ofb mode is being * used. The extra state information to record how much of the * 64bit block we have used is contained in *num; */void idea_ofb64_encrypt(in, out, length, schedule, ivec, num)unsigned char *in;unsigned char *o
17、ut;long length;IDEA_KEY_SCHEDULE *schedule;unsigned char *ivec;int *num;register unsigned long v0,v1,t;register int n= *num;register long l=length;unsigned char d8;register char *dp;unsigned long ti2;unsigned char *iv;int save=0;iv=(unsigned char *)ivec;n2l(iv,v0);n2l(iv,v1);ti0=v0;ti1=v1;dp=(char *
18、)d;l2n(v0,dp);l2n(v1,dp);while (l-)if (n = 0)idea_encrypt(unsigned long *)ti,schedule);dp=(char *)d;t=ti0; l2n(t,dp);t=ti1; l2n(t,dp);save+;*(out+)= *(in+)dn;n=(n+1)&0x07;if (save)v0=ti0;v1=ti1;iv=(unsigned char *)ivec;l2n(v0,iv);l2n(v1,iv);t=v0=v1=ti0=ti1=0;*num=n;#ifndef NOPROTOstatic IDEA_INT
19、 inverse(unsigned int xin);#elsestatic IDEA_INT inverse();#endifvoid idea_set_encrypt_key(key, ks)unsigned char *key;IDEA_KEY_SCHEDULE *ks;int i;register IDEA_INT *kt,*kf,r0,r1,r2;kt= &(ks->data00);n2s(key,kt0); n2s(key,kt1); n2s(key,kt2); n2s(key,kt3);n2s(key,kt4); n2s(key,kt5); n2s(key,kt6)
20、; n2s(key,kt7);kf=kt;kt+=8;for (i=0; i<6; i+)r2= kf1;r1= kf2;*(kt+)= (r2<<9) | (r1>>7)&0xffff;r0= kf3;*(kt+)= (r1<<9) | (r0>>7)&0xffff;r1= kf4;*(kt+)= (r0<<9) | (r1>>7)&0xffff;r0= kf5;*(kt+)= (r1<<9) | (r0>>7)&0xffff;r1= kf6;*(kt+)=
21、(r0<<9) | (r1>>7)&0xffff;r0= kf7;*(kt+)= (r1<<9) | (r0>>7)&0xffff;r1= kf0;if (i >= 5) break;*(kt+)= (r0<<9) | (r1>>7)&0xffff;*(kt+)= (r1<<9) | (r2>>7)&0xffff;kf+=8;void idea_set_decrypt_key(ek, dk)IDEA_KEY_SCHEDULE *ek;IDEA_KEY_SCHED
22、ULE *dk;int r;register IDEA_INT *fp,*tp,t;tp= &(dk->data00);fp= &(ek->data80);for (r=0; r<9; r+)*(tp+)=inverse(fp0);*(tp+)=(int)(0x10000L-fp2)&0xffff);*(tp+)=(int)(0x10000L-fp1)&0xffff);*(tp+)=inverse(fp3);if (r = 8) break;fp-=6;*(tp+)=fp4;*(tp+)=fp5;tp= &(dk->data00)
23、;t=tp1;tp1=tp2;tp2=t;t=tp49;tp49=tp50;tp50=t;/* taken directly from the 'paper' I'll have a look at it later */static IDEA_INT inverse(xin)unsigned int xin;long n1,n2,q,r,b1,b2,t;if (xin = 0)b2=0;elsen1=0x10001;n2=xin;b2=1;b1=0;dor=(n1%n2);q=(n1-r)/n2;if (r = 0) if (b2 < 0) b2=0x10001+b2; elsen1=n2;n2=r;t=b2;b2=b1-q*b2;b1=t; while (r != 0);return(IDEA_INT)b2);#include<stdio.h> /RSA算法int candp(int a,int b,int c)int r=1;b=b+1;while(b!=1)r=r*a;r=r%c;b-;printf("%dn",r);return r;int fun(int
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 资产买卖协议书
- 足疗店劳动合同协议书
- 跨境精细配送协议
- 软件技术合作与联盟合同
- 轻松掌握地理单词
- 迟到保证书格式与范文
- 配电箱设备保养计划
- 钢筋班组分包协议
- 鉴往知来担当历史使命
- 钻井设备租赁协议
- 2024年度宠物用品销售合同
- 低压电工作业(复审)模拟考试题库试卷
- GB/T 44831-2024皮肤芯片通用技术要求
- 农业气象学-作业4-国开(ZJ)-参考资料
- 2024年廉洁合作原则声明书
- EE-华为智慧供应链ISC规划项目-05业务服务化架构设计-2016
- 2024-2030年中国物业管理行业深度调研及发展模式分析报告
- 2022年大学物理学专业大学物理二期末考试试题-附解析
- 2024年广西普法考试答案8
- 数学-湖北华中师范大学一附中2024高二上数学周测和解析(11月2)
- Unit 4 Section B(1a-2b)(同步课件)-2024-2025学年初中英语七年级上册同步课件(人教版2024)
评论
0/150
提交评论