Version 10 of Password generator

Updated 2016-04-16 16:00:18 by bll

Should create a strong password:

variable _index [pid];

proc password {length} {
        global _index;
        variable _set {shW4UMe832TpaSylIdfzxbrNki9A7Q5PmZ0XDuYVg1KEGwLcJtjRCF6OqovBHn};
        variable _password {};

        for {set _char 1} {$_char <= $length} {incr _char} {
                incr _index [lindex [time {
                        while {$_index >= [string length $_set]} {
                                incr _index -[string length $_set];
                        }
                        
                        # Only usefull to increase entropy
                        
                        for {set _count $_index} {$_count <= [string length $_set]+[string index [clock microseconds] end]} {incr _count} {
                        
                                # Nothing to do

                        }
                        
                        set _password $_password[string index $_set $_index];
                }] 0]
        }

        return $_password;
}

Call password length inside the script.

AMG: My first instinct was to optimize this code since it is written in a seemingly wasteful way. However, there is a trick, a method to the madness. The time command is used as a random number generator, used to advance the index into the character set. So inefficient programming with somewhat unpredictable runtime is exactly the programmer's intent.

bll 2016-4-15:

See [L1 ]:

The output from "ent" for 80000 characters, password 8 called 10000 times. The serial correlation coefficient is quite high.

Entropy = 4.787082 bits per byte.

Optimum compression would reduce the size
of this 80000 byte file by 40 percent.

Chi square distribution for 80000 samples is 841393.86, and randomly
would exceed this value 0.01 percent of the times.

Arithmetic mean value of data bytes is 93.7709 (127.5 = random).
Monte Carlo value for Pi is 4.000000000 (error 27.32 percent).
Serial correlation coefficient is -0.204070 (totally uncorrelated = 0.0).

paskali 2016-04-15:

Thanks. I am crazy.


paskali - 2016-04-16 13:38:58

Update, now the previous test should be something like this:

Entropy = 5.953689 bits per byte.

Optimum compression would reduce the size
of this 80000 byte file by 25 percent.

Chi square distribution for 80000 samples is 250555.01, and randomly
would exceed this value less than 0.01 percent of the times.

Arithmetic mean value of data bytes is 86.9527 (127.5 = random).
Monte Carlo value for Pi is 4.000000000 (error 27.32 percent).
Serial correlation coefficient is 0.000435 (totally uncorrelated = 0.0).

bll 2016-4-16

The latest version:

See [L2 ]:

The output from "ent" for 80000 characters, password 8 called 10000 times. The serial correlation coefficient is very high. As seen from the character occurrence table, this is not a strong generator.

Entropy = 3.753542 bits per byte.

Optimum compression would reduce the size
of this 80000 byte file by 53 percent.

Chi square distribution for 80000 samples is 1668541.12, and randomly
would exceed this value 0.01 percent of the times.

Arithmetic mean value of data bytes is 101.3792 (127.5 = random).
Monte Carlo value for Pi is 4.000000000 (error 27.32 percent).
Serial correlation coefficient is -0.048597 (totally uncorrelated = 0.0).

The character occurence table:

Value Char Occurrences Fraction
 48   0           64   0.000800
 49   1           31   0.000387
 50   2           12   0.000150
 51   3           17   0.000212
 52   4           11   0.000138
 53   5          122   0.001525
 54   6           11   0.000138
 55   7          183   0.002288
 56   8           18   0.000225
 57   9         1063   0.013288
 65   A          277   0.003462
 66   B           12   0.000150
 67   C           17   0.000212
 68   D           64   0.000800
 69   E           25   0.000313
 70   F           17   0.000212
 71   G           15   0.000188
 72   H           10   0.000125
 73   I         6791   0.084888
 74   J           13   0.000162
 75   K           24   0.000300
 76   L           17   0.000212
 77   M           11   0.000138
 78   N         7556   0.094450
 79   O           14   0.000175
 80   P          111   0.001388
 81   Q          152   0.001900
 82   R            7   0.000087
 83   S          309   0.003863
 84   T           17   0.000212
 85   U           10   0.000125
 86   V           41   0.000513
 87   W           12   0.000150
 88   X           62   0.000775
 89   Y           52   0.000650
 90   Z           98   0.001225
 97   a          120   0.001500
 98   b         7842   0.098025
 99   c           13   0.000162
100   d         7534   0.094175
101   e           15   0.000188
102   f         7720   0.096500
103   g           21   0.000262
104   h           15   0.000188
105   i         3328   0.041600
106   j           21   0.000262
107   k         7020   0.087750
108   l         4747   0.059338
109   m          102   0.001275
110   n            8   0.000100
111   o           13   0.000162
112   p           15   0.000188
113   q           11   0.000138
114   r         7738   0.096725
115   s           15   0.000188
116   t           20   0.000250
117   u           46   0.000575
118   v           12   0.000150
119   w           19   0.000237
120   x         7718   0.096475
121   y          817   0.010212
122   z         7804   0.097550

Total:         80000   1.000000

See Also