Guest User

Untitled

a guest
May 7th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define MAX_ALLOWED_BYTES 256 * 256
  4. #define RANGE(x, y, z) ((x) >= (y) && (x) <= (z))
  5.  
  6. static int letter_count[256];
  7.  
  8. int main(int argc, char **argv)
  9. {
  10. char curr_letter;
  11. FILE *fp;
  12. int i, j;
  13.  
  14. puts(" -= SSCAT =-");
  15. puts("-= Serious Substition Cipher Analysis Tool =-\n");
  16.  
  17. if (argc < 2) {
  18. fprintf(stderr, "Please provide valid file(s) for Analysis!\n"
  19. "Usage: %s <File 1> <File 2> ... <File n>\n", argv[0]);
  20. return -1;
  21. }
  22.  
  23. memset(letter_count, 0x00, 256);
  24.  
  25. for (j = 1; j < argc; j++) {
  26. fp = fopen(argv[j], "rb");
  27.  
  28. if (fp == NULL) {
  29. fprintf(stderr, "Provided file %s is not valid!\n\n", argv[j]);
  30. continue;
  31. }
  32.  
  33. printf("Processing file %s now!\n", argv[j]);
  34.  
  35. for (i = 0; i < MAX_ALLOWED_BYTES && !feof(fp); i++) {
  36. curr_letter = getc(fp);
  37. letter_count[curr_letter]++;
  38.  
  39. if (i == MAX_ALLOWED_BYTES - 1)
  40. fprintf(stderr, "File %s is too big! Will not continue reading\n", argv[j]);
  41.  
  42. }
  43.  
  44. fclose(fp);
  45.  
  46. for (i = 0; i < 256; i++) {
  47. if (letter_count[i] != 0x00)
  48. if (RANGE(i, 'A', 'Z') || RANGE(i, 'a', 'z'))
  49. printf("Letter %c was found %d time(s)!\n", i, letter_count[i]);
  50. }
  51. }
  52.  
  53. sleep(1);
  54. puts("Analysis finished!");
  55. puts("Thanks for using SSCAT!");
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment