fork download
  1. #include <time.h> /* time */
  2. #include <stdio.h> /* FILE, fopen, fwrite, fclose, fprintf */
  3. #include <stdint.h> /* uint*_t int*_t */
  4. #include <string.h> /* strlen */
  5. #include <stdlib.h> /* srand, rand */
  6. #include <sys/stat.h> /* stat */
  7. #include <sys/types.h> /* off_t */
  8.  
  9. static uint8_t
  10. CorruptStep(const char *filename, const off_t filesize, const char *pattern)
  11. {
  12. uint8_t ret = 0;
  13.  
  14. FILE* fp = fopen(filename, "w");
  15. if (fp != NULL)
  16. {
  17. off_t i;
  18. uint8_t length = (uint8_t) strlen(pattern);
  19. if (length > 0)
  20. {
  21. off_t times = (filesize / length) + (filesize % length);
  22. for (i = 0; i < times; i++)
  23. {
  24. fwrite(pattern, sizeof(char), length, fp);
  25. }
  26. }
  27. else
  28. {
  29. srand((unsigned int) time(NULL));
  30. for (i = 0; i < filesize; i++)
  31. {
  32. int n = rand();
  33. fwrite(&n, sizeof(char), 1, fp);
  34. }
  35. }
  36. fclose(fp);
  37. }
  38. else
  39. {
  40. ret = 1;
  41. }
  42. return ret;
  43. }
  44.  
  45. static uint8_t
  46. CorruptFile(const char *filename)
  47. {
  48. uint8_t ret = 0;
  49.  
  50. struct stat st;
  51. if(stat(filename, &st) == 0)
  52. {
  53. if (S_ISREG(st.st_mode) != 0)
  54. {
  55. off_t filesize = st.st_size;
  56. const char* steps[35] = {"", "", "", "", "\x55", "\xAA",
  57. "\x92\x49\x24", "\x49\x24\x92",
  58. "\x24\x92\x49", "\x00", "\x11",
  59. "\x22", "\x33", "\x44", "\x55",
  60. "\x66", "\x77", "\x88", "\x99",
  61. "\xAA", "\xBB", "\xCC", "\xDD",
  62. "\xEE", "\xFF", "\x92\x49\x24",
  63. "\x49\x24\x92", "\x24\x92\x49",
  64. "\x6D\xB6\xDB", "\xB6\xDB\x6D",
  65. "\xDB\x6D\xB6", "", "", "", ""};
  66. uint8_t i;
  67. for (i = 0; i < 35; i++)
  68. {
  69. if (CorruptStep(filename, filesize, steps[i]) != 0)
  70. {
  71. fprintf(stderr, "corrupt: shredding of '%s' ", filename);
  72. fprintf(stderr, "failed on step %d\n", i);
  73. ret = 1;
  74. break;
  75. }
  76. }
  77. }
  78. else
  79. {
  80. fprintf(stderr, "corrupt: '%s' is not a regular file\n", filename);
  81. ret = 1;
  82. }
  83. }
  84. else
  85. {
  86. fprintf(stderr, "corrupt: '%s' not found\n", filename);
  87. ret = 1;
  88. }
  89. return ret;
  90. }
  91.  
  92. int
  93. main(int argc, char* argv[])
  94. {
  95. if (argc > 1)
  96. {
  97. int i;
  98. for (i = 1; i < argc; i++)
  99. {
  100. CorruptFile(argv[i]);
  101. }
  102. }
  103. else
  104. {
  105. fprintf(stderr, "Usage: corrupt FILES...\n");
  106. fprintf(stderr, "Shreds files using the Gutmann method\n");
  107. }
  108. return 0;
  109. }
  110.  
Success #stdin #stdout #stderr 0.01s 5284KB
stdin
/*  Berechnung des Hamming-Abstandes zwischen zwei 128-Bit Werten in 	*/
/*	einer Textdatei. 													*/
/*  Die Werte müssen auf einer separaten Zeile gespeichert sein			*/
/* 																		*/
/*	Erstellt: 17.5.2010													*/
/*  Autor: Thomas Scheffler												*/

#include <stdio.h>
#include <stdlib.h>

#define ARRAY_SIZE 32

unsigned Hamdist(unsigned x, unsigned y)
{
  unsigned dist = 0, val = x ^ y;
 
  // Count the number of set bits
  while(val)
  {
    ++dist; 
    val &= val - 1;
  }
 
  return dist;
}



int main (void)
{
	char hex;
	int i;
	int a[ARRAY_SIZE];
	int b[ARRAY_SIZE];
	int hamDist = 0;
	FILE* fp;
	
	//Arrays mit 0 initialisieren
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
  		a[i] = 0;
  		b[i] = 0;
	}

	
	fp = fopen("hex.txt","r");
	if (fp == NULL) 
	{
		printf("Die Datei hex.txt wurde nicht gefunden!");
		exit(EXIT_FAILURE);
	}

	i=0;
	printf("1.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
        a[i]=strtol(&hex,0,16);
		i++;
    }
	i=0;
	printf("2.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
    	b[i]=strtol(&hex,0,16);
        i++;
    }
	fclose(fp);

	printf("Hamming-Abweichung pro Nibble:\n");
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
		printf ("%i\t%i\t%i\n",a[i],b[i],Hamdist(a[i],b[i]));
		hamDist += Hamdist(a[i],b[i]);
	}
	printf ("\nHamming-Abweichung der Hash-Werte:%d\n",hamDist);
}

stdout
Standard output is empty
stderr
Usage: corrupt FILES...
Shreds files using the Gutmann method