English
HOME | PROJECTS | C++ CLASSES | c\c++ source code | Gallery | Guestbook | BW Servers | Contact me | Login

<< Vigenère cipher >>

visits: 3103


A small and bad written source code to obscure a text file with the Vigenerè cipher.

  1. //*************************************//
  2. //******** created by mamo139 *********//
  3. //*** http://mamo139.altervista.org ***//
  4. //*************************************//
  5.  
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. int main () {
  11.  
  12. char key[20]="chiave";
  13.  
  14.  
  15. FILE * pFile;
  16. pFile = fopen ( "input.txt" , "rb" );
  17. long lSize,b,x,keyl=strlen(key);
  18. printf("keyl: %d key: %s\n",keyl,key);
  19. fseek (pFile , 0 , SEEK_END);
  20. lSize = ftell (pFile);
  21. fclose (pFile);
  22.  
  23. pFile = fopen ( "input.txt" , "rb" );
  24. char *buf;
  25.  
  26. buf = (char *) malloc(lSize * sizeof(char));
  27.  
  28. b=fread( buf, 1, lSize, pFile);
  29. fclose (pFile);
  30.  
  31. FILE * f_out;
  32. f_out = fopen ( "output.txt" , "wb" );
  33.  
  34. for(x=0;x<b;x++){
  35. buf[x] = buf[x] + key[x%(keyl)];
  36.  
  37.  
  38. }
  39.  
  40. fwrite( buf, 1, b, f_out);
  41.  
  42.  
  43. fclose (f_out);
  44.  
  45.  
  46. return 0;
  47. }
  48.  
Website version: 1.03.01 by mamo139. - All the source codes are intended to be released under "GNU GPL version 3".