简单的加密,解密程序

//       朱大伟         20062479369
#include <stdio.h>
#define MAX 50
int k;//字符长度
char arry1[MAX],arry2[MAX],arry3[MAX];//加密后保留在arry2中
//********************加密**********************
void Secret()
{      
       char ch;        
       int i=0,j=0;
       printf("please input you want secret string:/n");
       while((ch=getchar())!='/n')
             {
                  arry1[i++]=ch;//第一次i=0
                  if(ch>='0'&&ch<='9')
                      if(ch+4>'9')
                          arry2[j++]=48+(ch+4)%58;
                      else   
                          arry2[j++]=(ch+4);//ascii码加4
                  if(ch>='a'&&ch<='z')
                      if(ch+4>'z')//超过上界
                          arry2[j++]=97+((ch+4)%123);
                      else
                           arry2[j++]=(ch+4);
                      if(ch>='A'&&ch<='Z')
                            if(ch+4>'Z')
                                  arry2[j++]=65+(ch+4)%91;
                            else
                                  arry2[j++]=(ch+4);
             }
           k=j;
         printf("The result is /n");       
         for(i=0;i<j;i++)
           printf("%c",arry2[i]);
}
 //******************解密*************************
 void N_Secret( )
     {
             int i,j=0;
             int k;
             char ch1; //解密后保留在arry3中
             for(i=0;i<k;i++)
                   { 
                      ch1=arry2[i];//逐个取加密后的字符      
                      if(ch1>='0'&&ch1<='9')
                          if(ch1-4<'0')
                             arry3[j++]=58-(48-(ch1-4));
                          else
                             arry3[j++]=ch1-4;    
                      if(ch1>='a'&&ch1<='z')
                         {
                            if(ch1-4<'a')
                               arry3[j++]=123-(97-(ch1-4));
                            else
                               arry3[j++]=(ch1-4);
                        }
                     if(ch1>='A'&&ch1<='Z')
                          {
                               if(ch1-4<'A')
                                  arry3[j++]=91-(65-(ch1-4));
                               else
                                  arry3[j++]=(ch1-4);   
                       } 
                    }
              printf("/nThe Jie mi result is /n");       
         for(i=0;i<j;i++)
           printf("%c",arry3[i]);
     }
   //****************主函数*******************          
 int main()
  {
       char ch;
       Secret();
       N_Secret();
       ch=getch();
       return 0;
  }
 
 

你可能感兴趣的:(c,加密,String,解密,input)