Advertisement
PAULDC

password encrytption

Mar 26th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.40 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <math.h>
  3. using namespace std
  4. #define EXP(z) (sqrt((z*z*z*z-z)/(2*z))
  5. char password[30];
  6. char a[30];
  7. int ASCI;
  8. FILE *fp;      
  9. void title(void);
  10.  
  11. void head(void);
  12.  
  13. void setup(void);            // for Setting up of password file
  14.  
  15. void confirm_pswrd(void);   //will ask for the password & confirm it
  16.  
  17. void process_pswrd(void);  //for processing the password
  18.  
  19. int Get_ASCI(char);        //for fetching the asci code
  20.  
  21. void encrypt(int);         //for encryption
  22.  
  23. void decode(void);         //For decoding
  24.  
  25. void input(void);          //for inputting the password
  26.  
  27. void choice(void);
  28.  
  29. int main()
  30.     {
  31.      title();
  32. //     confirm_pswrd();
  33.     return 0;
  34.     }
  35.    
  36. void confirm_pswrd(void)
  37.      {
  38.      fp=fopen("PASSWORD","r");
  39.      if(fp==NULL)
  40.                   setup();
  41.      else
  42.        {
  43.         int index;
  44.         fclose(fp);
  45.         input();
  46.         decode();
  47.         index=strcmp(password,a);
  48.         if(index==0)
  49.         {
  50.                   printf("THE PASSWORD IS RIGHT\n");
  51. //                  choice();
  52.         }
  53.         else
  54.         {
  55.                    system("clear");
  56.                    printf("THE PASSWORD IS WRONG\nPLEASE TRY AGAIN\n");
  57.                    confirm_pswrd();
  58.         }
  59.        }
  60.      }
  61.  
  62.  
  63.  
  64. int Get_ASCI(char x)
  65.     {
  66.     int k;
  67.     k=x;
  68.     return k;
  69.     }
  70.    
  71. void encrypt(y)
  72.      {
  73.      int k,n,i;
  74.      char ch;
  75.      n=sqrt((y*y*y*y-y)/(2*y));
  76.      fp=fopen("PASSWORD","a");
  77.      for(k=0,i=0;k<n;k++)
  78.              {
  79.              ch='*';
  80.              fputc(ch,fp);
  81.              }
  82.       ch=' ';
  83.       printf(" ");
  84.       fputc(ch,fp);
  85.       fclose(fp);
  86.      }
  87.      
  88. void process_pswrd(void)
  89.      {
  90.      int i;
  91.      for(i=0;i<=10;i++)
  92.         {
  93.         if(a[i]=='\0')
  94.           {
  95.           break;
  96.           }
  97.         else
  98.           {
  99.           ASCI=Get_ASCI(a[i]);
  100.           encrypt(ASCI);
  101.           }
  102.         }
  103.      }
  104.      
  105.      
  106. void decode(void)
  107.      {
  108.      int n[20],k,j=0,i,a,exp,d,z,y;
  109.      char ch;
  110.      fp=fopen("PASSWORD","r");
  111.     i=0;
  112.      while(ch!= EOF)
  113.                    {
  114.                     ch=fgetc(fp);
  115.                     if(ch=='*')
  116.                       {
  117.                         i++;
  118.  
  119.                       }
  120.                     else
  121.                       {
  122.                          if(ch!=EOF)
  123.                          {
  124.                          n[j]=i;
  125.                          i=0;
  126.                          j++;
  127.                          }
  128.                       }
  129.                     }
  130.      fclose(fp);
  131.      d=j-1;
  132.      for(i=0;i<=d;i++)
  133.         {
  134.         a=n[i];
  135.         for(k=1;k<=123;k++)
  136.            {
  137.            z=k;
  138.            y=k;
  139.            exp=sqrt((z*z*z*z-z)/(2*z));
  140.            if(a==exp)
  141.                         {
  142.                         password[i]=(char)y;
  143.                         }
  144.            }
  145.         }
  146.      }
  147.  
  148. void setup(void)
  149.      {
  150.        head();
  151.        printf("\n\n\t\t\tWELCOME TO SETUP WIZARD\n\n\n\n");
  152.        head();
  153.        printf("\n\nPlease input the new password :");
  154.        scanf("%s",a);        
  155.        process_pswrd();
  156.        confirm_pswrd();
  157.      }
  158.      
  159.      
  160. void input(void)
  161.      {
  162.      head();
  163.      printf("Enter the password\n");
  164.      scanf("%s",a);    
  165.      }
  166.  
  167. void choice(void)
  168.      {
  169.                   system("clear");
  170.                   printf("\n\n\n\n\n\n\t\t\tACCESS GRANTED");
  171.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement