home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / E-zine / Magazines / b4b0 / b4b0-07 / encrypt.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-27  |  2.6 KB  |  137 lines

  1. /* 
  2. |-----------------------------------------------------------------------|
  3. | Encrypt.c 
  4. | By tragen, coolny@geocities.com
  5. | Please mail me if you find any bugs, or problems
  6. | To use my program you have to use this command line :
  7. | ./encrypt <input_file> <output_file> <numral_passcode(ex 4523)> <e> or <d> depending if you want to <e>ncrypt or <d>ecrypt
  8. |------------------------------------------------------------------------| 
  9. */
  10. #include <stdio.h>
  11. #include <unistd.h>
  12. #include <fcntl.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15.  
  16. main (int argc, char *argv[])
  17. {
  18. long int e,a,a2,rannum;
  19. int infile, outfile, count;
  20. unsigned long int key, key1, key2, key3, key4, key5, key6, key7, key8, key9,key2i;
  21. unsigned long int key10,key11,key12,ss,sz;
  22. long unsigned int i = 0;
  23. int ds;
  24. char keystr;
  25. char myin[1];
  26. char myout[1];
  27. char *ifile, *ofile;
  28.  
  29. if(argc<4) {
  30.     printf("\n Coded By Tragen, bugs/comments goto coolny@geocities.com \n");
  31.     printf("\n usage: ");
  32.     printf(argv[0]);
  33.     printf(" <infile> <outfile> <numral password> <e> for encrypt <d> for decrypt \n");
  34.     exit(22);
  35.     }
  36.  
  37. ifile=argv[1];
  38. ofile=argv[2];
  39. key = atoi(argv[3]);
  40. if(key>100000000) {
  41.     printf("Numral password too big, shorten the length \n");
  42.     exit(23);
  43. }
  44. ds=*argv[4];
  45. sz = key * 10;
  46. ss = key * key;
  47.  
  48. infile = open(ifile, O_RDONLY);
  49. outfile = open(ofile, O_RDWR | O_CREAT | O_TRUNC, 0777);
  50. i = 1;
  51. if (ds == 101)
  52. {
  53.     
  54.     printf("Encrypting ...\n");
  55.     key1=ss-sz+4;
  56.     key2=ss-4*key;
  57.     key3=-ss+2*key+5;
  58.     key4=ss-6*key+6;
  59.     key5=2 * ss - 4;
  60.     
  61.     
  62. }
  63. else {
  64.     
  65.     printf("Decrypting ...\n");
  66.     key1=-ss+sz-4;
  67.     key2=-ss-4*-key;
  68.     key3=ss+2*-key-5;
  69.     key4=-ss-6*-key-6;
  70.     key5=-2 * ss + 4;
  71.  
  72. }
  73. i = 0;    
  74.  
  75. count=1;
  76.  
  77. while (( read (infile, myin, sizeof(myin))) > 0) {
  78.  
  79. if (ds == 101)    {
  80.     i++;
  81.       i = i + count;
  82. }
  83. else {
  84.     i--;
  85.     i = i - count;
  86. }
  87.  
  88.  
  89.     
  90.     switch (count) {
  91.     case 1:
  92.         key1 = key1 +i ; 
  93.         myout[0] = myin[0]+key1;
  94.         count++;
  95.         break;
  96.     case 2:
  97.         key2 = key2 +i ;
  98.         myout[0] = myin[0]-key2;
  99.         count++;
  100.         break;
  101.     case 3:
  102.         key3 = key3 +i ;
  103.         myout[0] = myin[0]+key3;
  104.         count++;
  105.         break;
  106.     case 4:
  107.         key4 = key4 +i ;
  108.         myout[0] = myin[0]-key4;
  109.         count++;
  110.         break;
  111.     
  112.     case 5:
  113.         key5 = key5 + i ;
  114.         myout[0] = myin[0]+key5;
  115.         count=1;
  116.         break;
  117.     
  118.     write(outfile, myout, sizeof(myout));
  119.     }
  120. if (ds == 101)    {
  121.     printf("\nDone Encrypting...");
  122.     printf("\n Encrypted %s", ifile);
  123.     printf(" to %s", ofile);
  124.     printf("\n");
  125.     
  126. }
  127. else {
  128. printf("\nDone Decrypting...");
  129.     
  130.     printf("\n Decrypted %s", ifile);
  131.     printf(" to %s", ofile);
  132.     printf("\n");
  133. }
  134. }
  135.  
  136.