Skip to content

Commit ff9cacf

Browse files
committed
v2.6: added listing options -l, -L, -Z, and -v option; chars use default
terminal color, not white
1 parent d4a95c7 commit ff9cacf

File tree

3 files changed

+77
-27
lines changed

3 files changed

+77
-27
lines changed

README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
**circle**: statistics ASCII circle for analysing byte entropy in files.
22

33
**circle** reads all bytes in a file, and counts and arranges them from 0x00 to 0xff. Then it calculates the Standard deviation (sigma) of the data, and arranges the 256 resulting buckets in a circle, in such a way that the distance from the centre is proportional to the byte value (with 0x00 at the center, and ...0xf0-0xff bytes the farthest from it). The char that represents each byte is proportional to the deviation from the mean, in fractions of the standard deviation.
4+
5+
From v2.6, the list of different bytes counted can be printed using options `-l`, `-L`, `-Z`. Values over the mean will be printed green, and below it, they will be red.
46

57
Installation
68
============
79

8-
**circle** can be installed (as **bytes-circle**) in latest **Ubuntu** and **Debian** using official repositories. Follow [these instructions](http://serverfault.com/questions/550855/how-to-add-debian-testing-repository-to-apt-get) for adding repositories to previous versions' linux distributions, and then just install as usual:
10+
**circle** can be installed (as **bytes-circle**) in **Ubuntu** and **Debian** using official repositories. Follow [these instructions](http://serverfault.com/questions/550855/how-to-add-debian-testing-repository-to-apt-get) for adding repositories to previous versions' linux distributions, and then just install as usual:
911

1012
$ sudo apt-get install bytes-circle
1113

@@ -51,22 +53,28 @@ Options for non-colored consoles (in this case chars represent increments of 0.5
5153

5254
$ bytes-circle -h
5355

54-
Show statistics about bytes contained in a file,
55-
as a circle graph of deviations from sigma.
56-
57-
Use:
58-
$ bytes-circle [-o {0|1|2|3}] [-Bbnruh] [-z {0-255}] [<filename>] [<filename>] ...
59-
60-
-o {0 | 1=no color | 2=numbers | 3=uncoloured numbers}
61-
-B : stop processing files on first error encountered
62-
-b : no color
63-
-n : numbers
64-
-r : restrict statistics to the byte buckets that appear
65-
in the file, not to the 256 default value.
66-
-u : uncoloured numbers (-b -n)
67-
-h : prints this help
68-
-z {0-255} : prints a 2nd circle centered on this byte (0==127 !)
69-
56+
circle v2.6 (goo.gl/TNh5dq)
57+
58+
Show statistics about bytes contained in a file,
59+
as a circle graph of deviations from sigma.
60+
61+
Use:
62+
$ circle [-o {0|1|2|3}] [-BblLZnruvh] [-z {0-255}] [<filename>] [<filename>] ...
63+
64+
-o {0 | 1=no color | 2=numbers | 3=uncoloured numbers}
65+
-B : stop processing files on first error encountered
66+
-b : no color
67+
-l : list number of bytes counted, from 0 to 255
68+
-L : list number of bytes counted, excluding zero valued
69+
-Z : list number of bytes counted, but only zero valued
70+
-n : numbers
71+
-r : restrict statistics to the byte buckets that appear
72+
in the file, not to the 256 default value.
73+
-u : uncoloured numbers (-b -n)
74+
-v : prints version
75+
-h : prints this help
76+
-z {0-255} : prints a 2nd circle centered on this byte (0==127 !)
77+
7078
License
7179
=======
7280

statistics.c

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
// v1.2 by circulosmeos, 2016-01.
66
// v2.1, v2.2 by circulosmeos, 2016-06.
77
// v2.3 by circulosmeos, 2016-07.
8-
// v2.4 by circulosmeos, 2016-12.
8+
// v2.4, v2.5 by circulosmeos, 2016-12.
9+
// v2.6 by circulosmeos, 2018-12.
910
// wp.me/p2FmmK-96
1011
// goo.gl/TNh5dq
1112
//
@@ -28,6 +29,8 @@ bool two_circles_flag = false;
2829

2930
bool restrict_statistics = false;
3031

32+
int list_bytes = 0;
33+
3134
int two_circles_value=0;
3235

3336

@@ -42,12 +45,20 @@ int main ( int argc, char *argv[] ) {
4245
}*/
4346

4447
int opt = 0;
45-
while ((opt = getopt(argc, argv, "z:o:bnuBrh")) != -1)
48+
while ((opt = getopt(argc, argv, "z:o:blLZnuBrvh")) != -1)
4649
switch(opt) {
4750
// help
4851
case 'h':
4952
print_help();
5053
return 1;
54+
// version
55+
case 'v':
56+
printf ("\n %s \n\n ", PACKAGE_STRING);
57+
for (i=0; i<MAX_SIGMA_CHAR; i++) {
58+
printf ("%c ", sigma_char[i] );
59+
}
60+
printf(" each represents 1/4*sigma\n\n");
61+
return 1;
5162
// two circles: specify which ascii value set at zero position
5263
case 'z':
5364
two_circles_flag=true;
@@ -82,6 +93,18 @@ int main ( int argc, char *argv[] ) {
8293
case 'b':
8394
color_flag=false;
8495
break;
96+
// list number of bytes
97+
case 'l':
98+
list_bytes=1;
99+
break;
100+
// list number of bytes, but not 0 valued
101+
case 'L':
102+
list_bytes=2;
103+
break;
104+
// list number of bytes, but only 0 valued
105+
case 'Z':
106+
list_bytes=3;
107+
break;
85108
// numbers with colours instead of ascii art
86109
case 'n':
87110
numbers_flag=true;
@@ -99,9 +122,10 @@ int main ( int argc, char *argv[] ) {
99122
bBreakOnFirstError=true;
100123
break;
101124
case '?':
102-
if (isprint (optopt))
125+
if (isprint (optopt)) {
103126
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
104-
else
127+
print_help();
128+
} else
105129
fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
106130
return 2;
107131
default:
@@ -307,7 +331,7 @@ int analyze_file(char *szFile) {
307331

308332
// reset colour use in terminal screen
309333
if (color_flag)
310-
printf("%s%s", RESET, KWHT);
334+
printf("%s", RESET);
311335

312336
if (two_circles_flag) {
313337
printf("\t 0 centered\t\t\t\t%d centered\n\n", two_circles_value);
@@ -342,10 +366,24 @@ int analyze_file(char *szFile) {
342366
for (i=0; readable_size>1024.0; i++)
343367
readable_size/=1024.0;
344368

345-
printf("size =\t%.2f %s, (%lld bytes)\n", readable_size, SIZE_UNITS[i], total_size);
369+
printf("size =\t%.2f %s, (%lld bytes)\n\n", readable_size, SIZE_UNITS[i], total_size);
346370

347-
if (color_flag)
348-
printf("%s", RESET);
371+
// print counted values of each byte if list_bytes > 0
372+
if ( list_bytes > 0 ) {
373+
for (i=0; i<=MAX_VALUE; i++) {
374+
if ( list_bytes == 1 || ( list_bytes == 2 && bytes[i] > 0LL ) ) {
375+
if (color_flag && bytes[i] > 0LL)
376+
printf("%s", ((double)bytes[i] >= mean)?KGRN:KRED );
377+
printf("[%d] = %lld\n", i, bytes[i] );
378+
if (color_flag && bytes[i] > 0LL)
379+
printf("%s", RESET);
380+
} else {
381+
if ( list_bytes == 3 && bytes[i] == 0LL )
382+
printf("[%d] = %lld\n", i, bytes[i] );
383+
}
384+
}
385+
printf("\n");
386+
}
349387

350388
return 0;
351389

@@ -400,14 +438,18 @@ void print_help() {
400438

401439
printf ("\n %s \n", PACKAGE_STRING);
402440
printf ("\n Show statistics about bytes contained in a file,\n as a circle graph of deviations from sigma.\n\n");
403-
printf (" Use:\n $ %s [-o {0|1|2|3}] [-Bbnruh] [-z {0-255}] [<filename>] [<filename>] ...\n\n",
441+
printf (" Use:\n $ %s [-o {0|1|2|3}] [-BblLZnruvh] [-z {0-255}] [<filename>] [<filename>] ...\n\n",
404442
PACKAGE_NAME);
405443
printf ("\t-o {0 | 1=no color | 2=numbers | 3=uncoloured numbers}\n"
406444
"\t-B : stop processing files on first error encountered\n"
407445
"\t-b : no color\n"
446+
"\t-l : list number of bytes counted, from 0 to 255\n"
447+
"\t-L : list number of bytes counted, excluding zero valued\n"
448+
"\t-Z : list number of bytes counted, but only zero valued\n"
408449
"\t-n : numbers\n"
409450
"\t-r : restrict statistics to the byte buckets that appear \n\t in the file, not to the 256 default value.\n"
410451
"\t-u : uncoloured numbers (-b -n)\n"
452+
"\t-v : prints version\n"
411453
"\t-h : prints this help\n"
412454
"\t-z {0-255} : prints a 2nd circle centered on this byte (0==127 !)\n\n"
413455
);

statistics_circle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#endif
5454

5555
#define PACKAGE_NAME "circle"
56-
#define PACKAGE_STRING "circle v2.5 (goo.gl/TNh5dq)"
56+
#define PACKAGE_STRING "circle v2.6 (goo.gl/TNh5dq)"
5757

5858
#define BUFFER_LENGTH 4096
5959

0 commit comments

Comments
 (0)