All pastes #1309195 Raw Edit

passPhrase entropy

public c v1 · immutable
#1309195 ·published 2009-01-15 15:35 UTC
rendered paste body
#include <stdio.h>#include <math.h>#include <sunmath.h>#include <ctype.h>int main(){    int chars[256];    int c=0;  // each character typecasted from ascii to int     int i, j;  //  for loop  control    int k=0;   //  number of different characters, each 'A' counts once.      int k1=0;  // total passphrase characters,	// initialization    for (i = 0; i < 256; i++)        chars[i] = 0;//char[i]= 0,0,0,0,0,,   0//i        0,1,2,3,4,,,255// only 32 - 126 is used // from blank to ~// read entire file// every character is counted.     while ((c = getchar()) != EOF)	{		if (isprint(c))        	++chars[c];//char[c]= 0,0,0,0,0,, 1,,  0//c        0,1,2,3,4,,65,,255		 if (isprint(c)) // total passphrase characters,			++k1;  // this one turns out to be 20	}	// printf("===>DEBUG<==== %ld \n", k1);// ASCII printable ranges from 32 is space to 126 is ~    for (i = 32; i < 127; ++i)    {        if (chars[i] == 0)            continue;// print once the ASCII number of the found char// if isblank print "spacebar" and frequency else        printf("%c: ", i); // and print the frequency        for (j = 0; j < chars[i]; ++j)	{            printf("#");			}// then print a new line        printf("\n");// and count the number of lines if ( chars[i] != 0)	k++;    } printf("the passphrase has %ld  ASCII characters \n", k1); printf("the passphrase has %ld different ASCII characters \n", k); printf("hence Glyph entropy is log 2 (%ld) =  %4.12lf  bits per Glyph \n", k, log2(k));printf("hence passPhrase entropy is  %ld *  log 2 (%ld) = %4.12lf  Shannon \n", k1  , k , k1*log2(k));    return 0;}/* cc  CharFrequencyHistogram.exe.c  -lsunmathbash-3.00$ ./a.out < input.txt  : #A: #~: #the passphrase has 3 different ASCII characters hence entropy 1.584963 different ASCII characters *//*bash-3.00$ ./a.out < input.txt a: #########################################################################c: ###d: #e: #f: #l: ##m: #n: #o: #r: #s: #t: #y: ###the passphrase has 13 different ASCII characters hence string entropy is 3.700440  *//*bash-3.00$ ./a.out < input.txt a: ##c: ###d: #e: #f: #l: ##m: #n: #o: #r: #s: #t: #y: ###the passphrase has 13 different ASCII characters hence string entropy is 3.700440  bash-3.00$ cat  input.txt cleftcamsynodlacyyr !"#$%&'()*+,-./*//* !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~*//*bash-3.00$ cc  CharFrequencyHistogram_00.c  -lsunmathbash-3.00$ ./a.out   < input.txt : #!: #": ##: #$: #%: #&: #': #(: #): #*: #+: #,: #-: #.: #/: #0: #1: #2: #3: #4: #5: #6: #7: #8: #9: #:: #;: #<: #=: #>: #?: #@: #A: #B: #C: #D: #E: #F: #G: #H: #I: #J: #K: #L: #M: #N: #O: #P: #Q: #R: #S: #T: #U: #V: #W: #X: #Y: #Z: #[: #\: #^: #_: #`: #a: #b: #c: #d: #e: #f: #g: #h: #i: #j: #k: #l: #m: #n: #o: #p: #q: #r: #s: #t: #u: #v: #w: #x: #y: #z: #{: #|: #}: #~: #the passphrase has 94  ASCII characters the passphrase has 94 different ASCII characters hence Glyph entropy is log 2 (94) =  6.554588851678  bits per Glyph hence passPhrase entropy is  94 *  log 2 (94) = 616.131352057698  Shannon bash-3.00$ */