我编的文字加密与解密程序;
大家可以试一试;点评一下;
不知大家还有没有什么好的加密与解密算法~
拿出来大家分享一下拉~~
[em2][em2][em2][em2][em2][em2][em2][em2][em2][em2][em2][em2][em2][em2][em2]
/*
*For encrypt and decrypt
*Made by Yangkun;
*Copyright Yk;
*Don't use it with out my permission
*My email 
a2a2yk@163.com/Date 2006.11.9 2:43
*/
#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
FILE *fpr,*fpw;
char in[200],ch,out[200],fin[30]="d:\in.txt",fout[30]="d:\out.txt";
char setway;
int chose;
void cpyright()
{printf("******************En&Decrypt************************");
 printf("\n*This program for encrypt and decrypt");
 printf("\n*Made by Yangkun");
 printf("\n*Copyright 2006~2007 Yk\n*Don't use it with out my permission\n*My email 
a2a2yk@163.com");
 printf("\n****************************************************");
}
void decrypt(char *in,int j)
{int i;
 for(i=0;i<j;i++)
   {if(*(in+i)>='A'&&*(in+i)<='Z') *(in+i)=*(in+i)+32;
    if(*(in+i)>='a'&&*(in+i)<='z') *(in+i)=*(in+i)+2;
    if(*(in+i)>'z'&&*(in+i)<='z'+2) *(in+i)=*(in+i)-26;
    printf("%c",*(in+i));
   }
}
void encrypt(char *in,int j)
{int i,k;
 for(i=0;i<j;i++)
   {if(*(in+i)>='a'&&*(in+i)<='z') *(in+i)=*(in+i)-32;
    if(*(in+i)>='A'&&*(in+i)<='Z')                    /*note: limit range of every char*/
      {*(in+i)=*(in+i)-2;
       if(*(in+i)>=('A'-2)&&*(in+i)<'A') *(in+i)=*(in+i)+26;
       k=random(2)+1;
       if(k==1&&*(in+i)>='A'&&*(in+i)<='Z'){*(in+i)=*(in+i)+32;}
       }
     printf("%c",*(in+i));
   }
}
void filemake()
{  int i=0;
   printf("\nDefaultFrom:d:\\in.txt\nDefaultTo:d:\\out.txt\nDo you want to change route?(Y/N): ");
    scanf("%c",&setway);
     if(setway=='Y'||setway=='y')
      {printf("From(way of date):");
       scanf("%s",fin);
        printf("To(way of date):");
        scanf("%s",fout);
       }
    fpr=fopen(fin,"rt");           /*note: don't use fpr=fopen("fin","rt");
                                             but use fpr=fopen(fin,"rt");      */
    if(fpr==NULL){printf("error");getch();exit(1);}
    fpw=fopen(fout,"wt");
    if(fpw==NULL){printf("error");getch();exit(1);}
    ch=fgetc(fpr);
    while(ch!=EOF)
     {*(in+i)=ch;
      putchar(*(in+i));
      ch=fgetc(fpr);
      i++;
      }
     putchar('\n');
     strcpy(out,in);     /*use out so that it will not change the source information*/
     if(chose==1)decrypt(out,i);
     if(chose==2)encrypt(out,i);
     i=0;
    while(out
!='\0')
      {fputc(out,fpw);
       i++;
      }
      printf("\nFinished");
}
int setsc()
{ int stf;
  printf("\n          1.Type From Keyboard");
    printf("\n          2.Get from File\n");
    printf("          chose: ");
    scanf("%d",&stf);
    getchar();
    return(stf);
}
void getin()
{char che;
 int i=0;
 printf("\nEnter Words(Use # to end)");
 che=getchar();
 while(che!='#')
 {*(in+i)=che;
  che=getchar();
  i++;
 }
  putchar('\n');
  printf("Go on?");
  i=0;
  che=in;
  while(che!='\0')    /*note use "!=" not "=="*/
  {putchar(che);
   che=in;
   i++;
  }
  getch();
     printf("\nDefaultTo:d:\out.txt\nDo you want to change route?(Y/N):  ");
      getchar();
      scanf("%c",&setway);
     if(setway=='y'||setway=='Y')
     {printf("To(way of date): ");scanf("%s",fout);}
     strcpy(out,in);     /*use out so that it will not change the source information*/
     encrypt(out,i);
    fpw=fopen(fout,"wt");
    if(fpw==NULL){printf("error");getch();exit(1);}
     i=0;
    while(out!='\0')
      {fputc(out,fpw);
       i++;
      }
      printf("\nFinished");
}
main()
{
 int st;
 randomize();
 h:
 clrscr();
 cpyright();
 printf("\n\n\n\n~~~~~~~~~~~~~~~~~~~~START~~~~~~~~~~~~~~~~~~~~~");
 printf("\n\n          1:Decrypt words");
 printf("\n          2:Encrypt words");
 printf("\n          3:Exit\n Choose(1 or 2):");
 scanf("%d",&chose);
 getchar();                       /*note: use getchar() to eat '\n' if you u use getch();error then;*/
 if(chose==1)
   {filemake();
   }
 else if(chose==2)
     { st=setsc();
       if(st==1){getin();}
       if(st==2)filemake();
      }
     else if(chose==3) exit(0);
          else goto h;
printf("\nend");
getch();
}
[em2][em2][em2][em2][em2][em2][em2][em2][em2][em2][em2][em2][em2][em2][ 此贴被a2a2yk在2006-11-12 18:29重新编辑 ]