Italiano
HOME | PROGETTI | CLASSI C++ | Sorgenti c\c++ | Galleria | Guestbook | Server BW | Contattami | Login

<< Cifrario di Vigenerč >>

visiste: 3119


Due righe di codice scritte male per crittografare un file di testo con il cifrario di Vigenerč.

  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.  
Versione sito: 1.03.01 by mamo139. - Tutti i sorgenti presenti su questo sito sono rilasciati sotto licenza "GNU GPL version 3".