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

<< Steganografia BMP >>

visiste: 6241


Questo programma serve per nascondere dentro a un'immagine bmp un qualsiasi file.
Il programma nasconde 8 bit ogni 24 (cioè 8bit per ogni pixel).

  1. //*************************************//
  2. //******** created by mamo139 *********//
  3. //*** http://mamo139.altervista.org ***//
  4. //*************************************//
  5.  
  6. #include <stdio.h>
  7. #include <windows.h>
  8.  
  9. unsigned char* dammibit(unsigned char numero);
  10. unsigned char dammichar(unsigned char *bits);
  11. /*
  12.   char *bits;
  13.   bits = new char [8];
  14.   bits = dammibit(154);
  15. */
  16.  
  17. int main (void){
  18.  
  19. char nomefileb[20];
  20. printf("nome del file base:");
  21. scanf("%s",nomefileb);
  22. printf("%s!\n",nomefileb);
  23. //peso supportabile dal file base con steganografia 3-3-2bit
  24. FILE * pFile;
  25. long lSize;
  26. pFile = fopen ( nomefileb , "rb" );
  27. fseek (pFile , 0 , SEEK_END);
  28. lSize = ftell (pFile);
  29. fclose (pFile);
  30. printf("massimo peso sostenibile: %d kb!\n",(lSize/(3*1024)));
  31.  
  32. char nomefiles[20];
  33. printf("nome del file da steganografare:");
  34. scanf("%s",nomefiles);
  35. printf("%s!\n",nomefiles);
  36. //peso del file da steganografare
  37. FILE * pFile2;
  38. long lSize2;
  39. pFile2 = fopen ( nomefiles , "rb" );
  40. fseek (pFile2 , 0 , SEEK_END);
  41. lSize2 = ftell (pFile2);
  42. fclose (pFile2);
  43. printf(" peso file da steganografare: %d kb... operazione ",(lSize2/1024));
  44. if((lSize2/1024)<(lSize/(3*1024))) printf("FATTIBILE \n\n");
  45. else {printf("NON FATTIBILE \n\n");return 0; }
  46.  
  47. //******************** inizio operazioni di steganografia ***************************//
  48. long lbuffer = 3; //byte letti alla volta nella base
  49. long lbuffer2 = lbuffer/3; //byte letti nel file
  50. printf("buffer impostato a %d bytes\n",lbuffer);
  51.  
  52. unsigned char *buf, *buf2; //buffer di lettura
  53. buf = new unsigned char [(lbuffer+54)]; //grandezza del buffer della base
  54. buf2 = new unsigned char [(lbuffer2+54)]; //grandezza del buffer del file
  55. FILE *base, *file, *f_out;
  56. if ((file = fopen(nomefiles, "rb")) &&(base = fopen(nomefileb, "rb")) && (f_out = fopen("cript.bmp", "wb"))){
  57.  
  58. printf("files aperti con successo!!\n");
  59.  
  60. size_t b,c; //byte letti
  61. long x=0; //variabile per il ciclo
  62. b = fread( buf, 1, 54, base);
  63. fwrite( buf, 1, b, f_out);
  64.  
  65. while( c = fread( buf2, 1, lbuffer2, file) ) {
  66. b = fread( buf, 1, lbuffer, base);
  67.  
  68. /* ciclo di steganografia */
  69. x=x+lbuffer; // x = numero di byte letti dalla base
  70.  
  71.  
  72. unsigned char *bits_f;
  73. bits_f = new unsigned char [8];
  74. bits_f = dammibit(buf2[0]);
  75.  
  76. unsigned char *bits_b1;
  77. bits_b1 = new unsigned char [8];
  78. bits_b1 = dammibit(buf[0]);
  79. unsigned char *bits_b2;
  80. bits_b2 = new unsigned char [8];
  81. bits_b2 = dammibit(buf[1]);
  82. unsigned char *bits_b3;
  83. bits_b3 = new unsigned char [8];
  84. bits_b3 = dammibit(buf[2]);
  85.  
  86. bits_b1[5] = bits_f[0];
  87. bits_b1[6] = bits_f[1];
  88. bits_b1[7] = bits_f[2];
  89. bits_b2[5] = bits_f[3];
  90. bits_b2[6] = bits_f[4];
  91. bits_b2[7] = bits_f[5];
  92. bits_b3[6] = bits_f[6];
  93. bits_b3[7] = bits_f[7];
  94.  
  95. buf[0] = dammichar(bits_b1);
  96. buf[1] = dammichar(bits_b2);
  97. buf[2] = dammichar(bits_b3);
  98.  
  99. if(x%1048575==0)
  100. printf("%d Mb\n",(x/1048576));
  101.  
  102. fwrite( buf, 1, b, f_out);
  103.  
  104.  
  105. }
  106.  
  107. //lbuffer = 120000;
  108. printf("buffer reimpostato a %d bytes\n",lbuffer);
  109. while( b = fread( buf, 1, lbuffer, base) ){
  110. fwrite( buf, 1, b, f_out);
  111. if(x%1048575==0)
  112. printf("%d Mb\n",(x/1048576));
  113. }
  114.  
  115. }
  116.  
  117. fclose(file);
  118. fclose(base);
  119. fclose(f_out);
  120.  
  121. system("PAUSE");
  122. return 1;
  123. }
  124.  
  125.  
  126. unsigned char* dammibit(unsigned char numero){
  127.  
  128. unsigned char *bits;
  129. bits = new unsigned char [8];
  130.  
  131. if(numero<128) bits[0] = 0; // cifra 1
  132. else { bits[0] = 1; numero = numero - 128; }
  133.  
  134. if(numero<64) bits[1] = 0; // cifra 2
  135. else { bits[1] = 1; numero = numero - 64; }
  136.  
  137. if(numero<32) bits[2] = 0; // cifra 3
  138. else { bits[2] = 1; numero = numero - 32; }
  139.  
  140. if(numero<16) bits[3] = 0; // cifra 4
  141. else { bits[3] = 1; numero = numero - 16; }
  142.  
  143. if(numero<8) bits[4] = 0; // cifra 5
  144. else { bits[4] = 1; numero = numero - 8; }
  145.  
  146. if(numero<4) bits[5] = 0; // cifra 6
  147. else { bits[5] = 1; numero = numero - 4; }
  148.  
  149. if(numero<2) bits[6] = 0; // cifra 7
  150. else { bits[6] = 1; numero = numero - 2; }
  151.  
  152. if(numero<1) bits[7] = 0; // cifra 8
  153. else { bits[7] = 1; numero = numero - 1; }
  154. /*
  155.   FILE *prova = fopen("output.txt","wb");
  156.   fwrite( bits, 1, 8, prova);
  157.   fclose(prova);
  158. */
  159. return bits;
  160.  
  161. }
  162.  
  163. unsigned char dammichar(unsigned char *bits){
  164.  
  165. unsigned char numero;
  166.  
  167. numero = bits[0]*128 + bits[1]*64 + bits[2]*32 + bits[3]*16 + bits[4]*8 + bits[5]*4 + bits[6]*2 + bits[7]*1;
  168.  
  169. return numero;
  170.  
  171. }


  1. //*************************************//
  2. //******** created by mamo139 *********//
  3. //*** http://mamo139.altervista.org ***//
  4. //*************************************//
  5.  
  6. #include <stdio.h>
  7. #include <windows.h>
  8.  
  9. unsigned char* dammibit(unsigned char numero);
  10. unsigned char dammichar(unsigned char *bits);
  11.  
  12.  
  13. int main (void){
  14.  
  15. char nomefileb[20];
  16. printf("nome del file base:");
  17. scanf("%s",nomefileb);
  18. printf("%s!\n",nomefileb);
  19.  
  20.  
  21. //******************** inizio operazioni di steganografia ***************************//
  22. long lbuffer = 3; //byte letti alla volta nella base
  23. long lbuffer2 = lbuffer/3; //byte letti nel file
  24. printf("buffer impostato a %d bytes\n",lbuffer);
  25.  
  26. unsigned char *buf; //buffer di lettura
  27. buf = new unsigned char [(lbuffer+54)]; //grandezza del buffer della base
  28. FILE *base, *f_out;
  29. if ((base = fopen(nomefileb, "rb")) && (f_out = fopen("decript.dcrp", "wb"))){
  30.  
  31. printf("files aperti con successo!!\n");
  32.  
  33. size_t b,c; //byte letti
  34. long x=0; //variabile per il ciclo
  35. b = fread( buf, 1, 54, base);
  36. while( b = fread( buf, 1, lbuffer, base) ) {
  37.  
  38. /* ciclo di steganografia */
  39. x=x+lbuffer; // x = numero di byte letti dalla base
  40.  
  41.  
  42. unsigned char *bits_f;
  43. bits_f = new unsigned char [8];
  44.  
  45. unsigned char *bits_b1;
  46. bits_b1 = new unsigned char [8];
  47. bits_b1 = dammibit(buf[0]);
  48. unsigned char *bits_b2;
  49. bits_b2 = new unsigned char [8];
  50. bits_b2 = dammibit(buf[1]);
  51. unsigned char *bits_b3;
  52. bits_b3 = new unsigned char [8];
  53. bits_b3 = dammibit(buf[2]);
  54.  
  55. bits_f[0]=bits_b1[5];
  56. bits_f[1]=bits_b1[6];
  57. bits_f[2]=bits_b1[7];
  58. bits_f[3]=bits_b2[5];
  59. bits_f[4]=bits_b2[6];
  60. bits_f[5]=bits_b2[7];
  61. bits_f[6]=bits_b3[6];
  62. bits_f[7]=bits_b3[7];
  63.  
  64. buf[0] = dammichar(bits_f);
  65.  
  66.  
  67. if(x%1048575==0)
  68. printf("%d Mb\n",(x/1048576));
  69.  
  70. fwrite( buf, 1, 1, f_out);
  71.  
  72.  
  73. }
  74. }
  75.  
  76. fclose(base);
  77. fclose(f_out);
  78.  
  79. system("PAUSE");
  80. return 1;
  81. }
  82.  
  83.  
  84. unsigned char* dammibit(unsigned char numero){
  85.  
  86. unsigned char *bits;
  87. bits = new unsigned char [8];
  88.  
  89. if(numero<128) bits[0] = 0; // cifra 1
  90. else { bits[0] = 1; numero = numero - 128; }
  91.  
  92. if(numero<64) bits[1] = 0; // cifra 2
  93. else { bits[1] = 1; numero = numero - 64; }
  94.  
  95. if(numero<32) bits[2] = 0; // cifra 3
  96. else { bits[2] = 1; numero = numero - 32; }
  97.  
  98. if(numero<16) bits[3] = 0; // cifra 4
  99. else { bits[3] = 1; numero = numero - 16; }
  100.  
  101. if(numero<8) bits[4] = 0; // cifra 5
  102. else { bits[4] = 1; numero = numero - 8; }
  103.  
  104. if(numero<4) bits[5] = 0; // cifra 6
  105. else { bits[5] = 1; numero = numero - 4; }
  106.  
  107. if(numero<2) bits[6] = 0; // cifra 7
  108. else { bits[6] = 1; numero = numero - 2; }
  109.  
  110. if(numero<1) bits[7] = 0; // cifra 8
  111. else { bits[7] = 1; numero = numero - 1; }
  112. /*
  113.   FILE *prova = fopen("output.txt","wb");
  114.   fwrite( bits, 1, 8, prova);
  115.   fclose(prova);
  116. */
  117. return bits;
  118.  
  119. }
  120.  
  121. unsigned char dammichar(unsigned char *bits){
  122.  
  123. unsigned char numero;
  124.  
  125. numero = bits[0]*128 + bits[1]*64 + bits[2]*32 + bits[3]*16 + bits[4]*8 + bits[5]*4 + bits[6]*2 + bits[7]*1;
  126.  
  127. return numero;
  128.  
  129. }
Versione sito: 1.03.01 by mamo139. - Tutti i sorgenti presenti su questo sito sono rilasciati sotto licenza "GNU GPL version 3".