




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、單表查詢:#include <stdio.h>#include <iostream>char M100;char C100;void jiami();void jiemi();void main()int choice;printf("加密請輸入數(shù)字1,解密請輸入數(shù)字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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 水產(chǎn)養(yǎng)殖基地土地使用權(quán)合同
- 公司技術(shù)服務(wù)采購合同
- 豪華酒店廚師服務(wù)合同
- 電子產(chǎn)品購銷合同標準版
- 房地產(chǎn)投資專項法律服務(wù)合同
- (完整版)農(nóng)村土地租賃合同書
- 光學玻璃的紫外光固化涂層技術(shù)考核試卷
- 醫(yī)療用品行業(yè)服務(wù)平臺拓展考核試卷
- 搪瓷原材料市場動態(tài)與價格趨勢考核試卷
- 數(shù)字出版物的長期保存與數(shù)字遺產(chǎn)考核試卷
- (完整word版)體檢報告單模版
- 船廠安全用電培訓課件
- 新型抗腫瘤藥物臨床應用指導原則
- 中國居民膳食指南(全)
- Boomer-XL3D鑿巖臺車(修訂版)
- 幼兒園小班故事《貪吃的小豬》課件
- 三年級(下)道德與法治第三單元教材分析課件
- Passport評估工具:項目復雜度評估表
- 南寧鐵路局招聘2023年高校畢業(yè)生133人筆試參考題庫(共500題)答案詳解版
- 軍用飛機改進方案
- 新版-GSP-:中藥材、中藥飲片知識培訓試題及答案
評論
0/150
提交評論