From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/stats.c | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/stats.c (limited to 'reference/C/CONTRIB/SNIP/stats.c') diff --git a/reference/C/CONTRIB/SNIP/stats.c b/reference/C/CONTRIB/SNIP/stats.c new file mode 100755 index 0000000..c17f8d6 --- /dev/null +++ b/reference/C/CONTRIB/SNIP/stats.c @@ -0,0 +1,53 @@ +/****************************************************************/ +/* */ +/* Collect file statistics */ +/* */ +/* Public domain demo program for analyzing encrypted */ +/* files. By: Bob Stout */ +/* */ +/****************************************************************/ + +#include +#include +#include +#include + +main(int argc, char *argv[]) +{ + int i, ch, hist = 0; + long n = 0L; + double mean = 0., stdev = 0., ftmp; + static unsigned bins[256]; + FILE *infile; + + assert(infile = fopen(argv[1], "rb")); + while (!feof(infile)) + { + if (EOF == (ch = fgetc(infile))) + break; + bins[ch] += 1; + ++n; + } + fclose(infile); + for (i = 0; i < 256; ++i) + { + mean += (double)(bins[i]); + if (bins[i]) + ++hist; + } + mean /= 256.; + for (i = 0; i < 256; ++i) + { + ftmp = (double)(bins[i]) - mean; + stdev += (ftmp * ftmp); + } + ftmp = stdev / 255.; + stdev = sqrt(ftmp); + printf("%ld Characters were read from %s\n" + "There are an average of %f occurances of each character\n" + "%d Characters out of 256 possible were used\n" + "The standard deviation is %f\n" + "The coefficient of variation is %f%%\n", + n, argv[1], mean, hist, stdev, (100. * stdev) / mean); + return EXIT_SUCCESS; +} -- cgit v1.2.3-54-g00ecf