牲口才开电车 e自由电子
关注数: 51 粉丝数: 494 发帖数: 26,682 关注贴吧数: 17
永不可能破解的文件加密解密算法 代码是windows版的,一下午的成果。。。。 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <windows.h> #define Nwheel 7 #define KEY 666 int wheel[Nwheel][256]; int iwheel[Nwheel][256]; int position[Nwheel]; int initial_position[Nwheel]; void swap(int *x, int *y) { int buff = *x; *x = *y; *y = buff; } int shuffle(int *A,int n) { int i,j; for(i=0;i<n;i++) { A[i]=i; } for(i=n;i>1;i--) { j=rand()%i; swap(&A[i-1],&A[j]); } return 0; } int init_wheel() { int i,j; for(i=0;i<Nwheel;i++) { shuffle(wheel[i],256); for(j=0;j<256;j++) { iwheel[i][wheel[i][j]]=j; } } return 0; } int Trans(FILE *fi,FILE *fo) { int i; for(i=0;i<Nwheel;i++) { position[i]=initial_position[i]; } int h; char c; while(!feof(fi)) { h = fgetc(fi); if(h != EOF) { for(i=0;i<Nwheel;i++) { h+=position[i]; h=h%256; h=wheel[i][h]; } c=h; fputc(c, fo); position[0]++; for(i=0;i<Nwheel-1;i++) { if(position[i]==256) { position[i]=0; position[i+1]++; } } if(position[Nwheel-1]==256) { position[Nwheel-1]=0; } } } return 0; } int iTrans(FILE *fi,FILE *fo) { int i; for(i=0;i<Nwheel;i++) { position[i]=initial_position[i]; } int h; char c; while(!feof(fi)) { h = fgetc(fi); if(h != EOF) { for(i=Nwheel-1;i>=0;i--) { h=iwheel[i][h]; h-=position[i]; if(h<0) { h+=256; } h=h%256; } c=h; fputc(c, fo); position[0]++; for(i=0;i<Nwheel-1;i++) { if(position[i]==256) { position[i]=0; position[i+1]++; } } if(position[Nwheel-1]==256) { position[Nwheel-1]=0; } } } return 0; } int main() { srand(KEY); init_wheel(); char filename[555],outputfile[555]; FILE *fi,*fo,*buff1,*buff2; int op; while(1) { system("cls"); printf("input file path:\n"); gets(filename); fi=fopen(filename,"rb"); if(fi==NULL) { system("cls"); printf("fail to open the file\n"); Sleep(2000); goto next; } printf("output file name:\n"); gets(outputfile); fo=fopen(outputfile,"wb"); printf("1:encrypt 2:decrypt\n"); scanf("%d",&op); if(op==1) { printf("encrypting..."); Trans(fi,fo); } else if(op==2) { printf("decrypting..."); iTrans(fi,fo); } fclose(fi); fclose(fo); system("cls"); printf("done"); Sleep(2000); getchar(); next:; } return 0; }
首页 3 4 5 6 7 8 下一页