Of these three, I prefer the shell. (I know, I'm as surprised as you.)

Please use this version, unless there's a compelling reason to prefer
Python:

#!/bin/bash
data=$(dd if=/dev/urandom bs=1 count=13 2>/dev/null| base32 | tr 'A-Z' 'a-z')
echo ${data:0:4}-${data:4:4}-${data:8:4}-${data:12:4}-${data:16:4}


Why I prefer the shell version, and an important change I made to it:

The shell script executes in roughly 20% the time of the python scripts.
(4s vs 22s for 1000 iterations.)

We should be selecting 13 bytes, not 12, from /dev/urandom. (I'll show
why near the end.)

The very long python script has an unexpected behavior, so if this is
the version that is selected, it needs the same .rstrip('=') treatment
as the short one:

$ ./uuid1.py
376y-fuyc-d5a7-6sjz-uhwa-====


When playing with the shell script I thought I noticed patterns in the last 
character of the output so I investigated further to make sure that these are 
actually emitting roughly what we expect:


$ for i in `seq 1 10000`; do ./uuid ; done | ent -c
Value Char Occurrences Fraction
 10            10000   0.040000
 45   -        40000   0.160000
 50   2         6056   0.024224
 51   3         5860   0.023440
 52   4         5946   0.023784
 53   5         6102   0.024408
 54   6         5951   0.023804
 55   7         5731   0.022924
 97   a        10761   0.043044
 98   b         5887   0.023548
 99   c         5847   0.023388
100   d         5938   0.023752
101   e         5929   0.023716
102   f         5936   0.023744
103   g         5922   0.023688
104   h         5934   0.023736
105   i         5940   0.023760
106   j         5834   0.023336
107   k         5997   0.023988
108   l         6005   0.024020
109   m         5940   0.023760
110   n         6026   0.024104
111   o         6081   0.024324
112   p         5909   0.023636
113   q        10947   0.043788
114   r         5918   0.023672
115   s         5892   0.023568
116   t         5908   0.023632
117   u         6033   0.024132
118   v         5912   0.023648
119   w         5934   0.023736
120   x         6067   0.024268
121   y         5892   0.023568
122   z         5965   0.023860

Total:        250000   1.000000


$ for i in `seq 1 10000`; do ./uuid1.py ; done | ent -c
Value Char Occurrences Fraction
 10            10000   0.033333
 45   -        50000   0.166667
 50   2         5953   0.019843
 51   3         5972   0.019907
 52   4         5893   0.019643
 53   5         5943   0.019810
 54   6         5940   0.019800
 55   7         5770   0.019233
 61   =        40000   0.133333 # ====
 97   a        10872   0.036240
 98   b         6011   0.020037
 99   c         5957   0.019857
100   d         5879   0.019597
101   e         5840   0.019467
102   f         5888   0.019627
103   g         5890   0.019633
104   h         5827   0.019423
105   i         5979   0.019930
106   j         5921   0.019737
107   k         5987   0.019957
108   l         5953   0.019843
109   m         6083   0.020277
110   n         5886   0.019620
111   o         6054   0.020180
112   p         5856   0.019520
113   q        10923   0.036410
114   r         6013   0.020043
115   s         5894   0.019647
116   t         6021   0.020070
117   u         6038   0.020127
118   v         5859   0.019530
119   w         5928   0.019760
120   x         6000   0.020000
121   y         5939   0.019797
122   z         6031   0.020103

Total:        300000   1.000000


$ for i in `seq 1 10000`; do ./uuid2.py ; done | ent -c
Value Char Occurrences Fraction
 10            10000   0.040000
 45   -        40000   0.160000
 50   2         5967   0.023868
 51   3         5954   0.023816
 52   4         5864   0.023456
 53   5         5849   0.023396
 54   6         5967   0.023868
 55   7         5985   0.023940
 97   a        11095   0.044380
 98   b         5892   0.023568
 99   c         5963   0.023852
100   d         5847   0.023388
101   e         5909   0.023636
102   f         5939   0.023756
103   g         5893   0.023572
104   h         5938   0.023752
105   i         6000   0.024000
106   j         6019   0.024076
107   k         5887   0.023548
108   l         5947   0.023788
109   m         5935   0.023740
110   n         5965   0.023860
111   o         6186   0.024744
112   p         5999   0.023996
113   q        10918   0.043672
114   r         5966   0.023864
115   s         5755   0.023020
116   t         5820   0.023280
117   u         5935   0.023740
118   v         5858   0.023432
119   w         5881   0.023524
120   x         5997   0.023988
121   y         6039   0.024156
122   z         5831   0.023324

Total:        250000   1.000000


The output is far more balanced if we select 13 bytes, instead of 12:

$ cat uuid13 
#!/bin/bash
data=$(dd if=/dev/urandom bs=1 count=13 2>/dev/null| base32 | tr 'A-Z' 'a-z')
echo ${data:0:4}-${data:4:4}-${data:8:4}-${data:12:4}-${data:16:4}

$ for i in `seq 1 10000`; do ./uuid13 ; done | ent -c
Value Char Occurrences Fraction
 10            10000   0.040000
 45   -        40000   0.160000
 50   2         6208   0.024832
 51   3         6378   0.025512
 52   4         6241   0.024964
 53   5         6384   0.025536
 54   6         6273   0.025092
 55   7         6217   0.024868
 97   a         6214   0.024856
 98   b         6185   0.024740
 99   c         6279   0.025116
100   d         6235   0.024940
101   e         6174   0.024696
102   f         6230   0.024920
103   g         6213   0.024852
104   h         6230   0.024920
105   i         6305   0.025220
106   j         6296   0.025184
107   k         6218   0.024872
108   l         6200   0.024800
109   m         6316   0.025264
110   n         6291   0.025164
111   o         6260   0.025040
112   p         6145   0.024580
113   q         6409   0.025636
114   r         6347   0.025388
115   s         6233   0.024932
116   t         6157   0.024628
117   u         6131   0.024524
118   v         6192   0.024768
119   w         6302   0.025208
120   x         6251   0.025004
121   y         6242   0.024968
122   z         6244   0.024976

Total:        250000   1.000000

Entropy = 4.866248 bits per byte.

(The same change in the Python versions also improves their distribution
of outputs.)

Thanks

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2073269

Title:
  Replace radsecret script to avoid new perl dependencies from universe

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/freeradius/+bug/2073269/+subscriptions


-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to