fork download
  1. #define MAX_TITKOS 10000
  2. #define OLVASAS_BUFFER 512
  3. #define KULCS_MERET 6
  4. #define _GNU_SOURCE
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include <string.h>
  10.  
  11. double
  12. atlagos_szohossz (const char *titkos, int titkos_meret)
  13. {
  14. int sz = 0;
  15. for (int i = 0; i < titkos_meret; ++i)
  16. if (titkos[i] == ' ')
  17. ++sz;
  18.  
  19. return (double) titkos_meret / sz;
  20. }
  21.  
  22. int
  23. tiszta_lehet (const char *titkos, int titkos_meret)
  24. {
  25. // a tiszta szoveg valszeg tartalmazza a gyakori magyar szavakat
  26. // illetve az átlagos szóhossz vizsgálatával csökkentjük a
  27. // potenciális töréseket
  28.  
  29. double szohossz = atlagos_szohossz (titkos, titkos_meret);
  30.  
  31. return szohossz > 6.0 && szohossz < 9.0
  32. && strcasestr (titkos, "hogy") && strcasestr (titkos, "nem")
  33. && strcasestr (titkos, "az") && strcasestr (titkos, "ha");
  34.  
  35. }
  36.  
  37. void
  38. exor (const char kulcs[], int kulcs_meret, char titkos[], int titkos_meret, char* buffer)
  39. {
  40.  
  41. int kulcs_index = 0;
  42.  
  43. for (int i = 0; i < titkos_meret; ++i)
  44. {
  45.  
  46. buffer[i] = titkos[i] ^ kulcs[kulcs_index];
  47. kulcs_index = (kulcs_index + 1) % kulcs_meret;
  48.  
  49. }
  50.  
  51. }
  52.  
  53. void
  54. exor_tores (const char kulcs[], int kulcs_meret, char titkos[],
  55. int titkos_meret)
  56. {
  57. char *buffer;
  58.  
  59. if ((buffer = (char *)malloc(sizeof(char)*titkos_meret)) == NULL)
  60. {
  61. printf("Memoria szetbombazva...\n");
  62. exit(-1);
  63. }
  64.  
  65. exor (kulcs, kulcs_meret, titkos, titkos_meret, buffer);
  66.  
  67. if (tiszta_lehet (buffer, titkos_meret))
  68. printf("Kulcs: [%s]\nTiszta szoveg: %s\n", kulcs, buffer);
  69.  
  70. free(buffer);
  71. }
  72.  
  73. int
  74. main (void)
  75. {
  76.  
  77. char titkos[MAX_TITKOS];
  78. char* p = titkos;
  79. int olvasott_bajtok;
  80. unsigned int key;
  81.  
  82. // titkos fajt berantasa
  83. while ((olvasott_bajtok =
  84. read (0, (void *) p,
  85. (p - titkos + OLVASAS_BUFFER <
  86. MAX_TITKOS) ? OLVASAS_BUFFER : titkos + MAX_TITKOS - p)))
  87. p += olvasott_bajtok;
  88.  
  89. // maradek hely nullazasa a titkos bufferben
  90. for (int i = 0; i < MAX_TITKOS - (p - titkos); ++i)
  91. titkos[p - titkos + i] = '\0';
  92.  
  93. // osszes kulcs eloallitasa
  94. #pragma omp parallel for
  95. for (key = 0; key < 1000000; key++)
  96. {
  97. char* kulcs;
  98.  
  99. if ((kulcs = (char *)malloc(sizeof(char)*KULCS_MERET)) == NULL)
  100. {
  101. printf("Memoria szetbombazva...\n");
  102. exit(-1);
  103. }
  104.  
  105. sprintf(kulcs, "%.6d", key);
  106.  
  107. exor_tores (kulcs, KULCS_MERET, titkos, p - titkos);
  108. free(kulcs);
  109.  
  110. if (key % 10000000 == 0) printf("PARAM");
  111. }
  112.  
  113.  
  114. return 0;
  115. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘atlagos_szohossz’:
prog.c:15: error: ‘for’ loop initial declaration used outside C99 mode
prog.c: In function ‘exor’:
prog.c:43: error: ‘for’ loop initial declaration used outside C99 mode
prog.c: In function ‘main’:
prog.c:90: error: ‘for’ loop initial declaration used outside C99 mode
prog.c:94: warning: ignoring #pragma omp parallel
stdout
Standard output is empty