
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.76 KB | hits: 22 | expires: Never
#include <stdio.h>
#define MAX_ALLOWED_BYTES 256 * 256
#define RANGE(x, y, z) ((x) >= (y) && (x) <= (z))
static int letter_count[256];
int main(int argc, char **argv)
{
char curr_letter;
FILE *fp;
int i, j;
puts(" -= SSCAT =-");
puts("-= Serious Substition Cipher Analysis Tool =-\n");
if (argc < 2) {
fprintf(stderr, "Please provide valid file(s) for Analysis!\n"
"Usage: %s <File 1> <File 2> ... <File n>\n", argv[0]);
return -1;
}
memset(letter_count, 0x00, 256);
for (j = 1; j < argc; j++) {
fp = fopen(argv[j], "rb");
if (fp == NULL) {
fprintf(stderr, "Provided file %s is not valid!\n\n", argv[j]);
continue;
}
printf("Processing file %s now!\n", argv[j]);
for (i = 0; i < MAX_ALLOWED_BYTES && !feof(fp); i++) {
curr_letter = getc(fp);
letter_count[curr_letter]++;
if (i == MAX_ALLOWED_BYTES - 1)
fprintf(stderr, "File %s is too big! Will not continue reading\n", argv[j]);
}
fclose(fp);
for (i = 0; i < 256; i++) {
if (letter_count[i] != 0x00)
if (RANGE(i, 'A', 'Z') || RANGE(i, 'a', 'z'))
printf("Letter %c was found %d time(s)!\n", i, letter_count[i]);
}
}
sleep(1);
puts("Analysis finished!");
puts("Thanks for using SSCAT!");
return 0;
}