You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -34,18 +34,9 @@ Efficiently generate cryptographically strong random strings of specified entrop
34
34
35
35
### <aname="TLDR"></a>TL;DR
36
36
37
-
##### Examples
38
-
39
-
Run the examples file using
40
-
41
-
```bash
42
-
yarn examples
43
-
node dist/examples.js
44
-
```
45
-
46
37
##### Example Usage
47
38
48
-
OWASP session ID using base32 characters:
39
+
OWASP session ID using base 32 characters:
49
40
```js
50
41
import {Random} from'entropy-string'
51
42
@@ -112,6 +103,15 @@ Base 64 character string with a 1 in a trillion chance of a repeat in 100 millio
112
103
113
104
> emzRPXRudAjZnOme
114
105
106
+
##### Examples
107
+
108
+
Run any of the examples in the `examples` directory by:
109
+
110
+
```bash
111
+
yarn examples
112
+
node examples/dist/tldr.js
113
+
```
114
+
115
115
[TOC](#TOC)
116
116
117
117
### <aname="Overview"></a>Overview
@@ -398,7 +398,7 @@ The 3rd option above will throw an `Error` if the characters string isn't approp
398
398
399
399
### <aname="Efficiency"></a>Efficiency
400
400
401
-
To efficiently create random strings, `entropy-string` generates the necessary number of bytes needed for each string and uses those bytes in a bit shifting scheme to index into a character set. For example, consider generating strings from the `base32` character set. There are __32__ characters in the set, so an index into an array of those characters would be in the range `[0,31]`. Generating a random string of `base32` characters is thus reduced to generating a random sequence of indices in the range `[0,31]`.
401
+
To efficiently create random strings, `entropy-string` generates the necessary number of bytes needed for each string and uses those bytes in a bit shifting scheme to index into a character set. For example, consider generating strings from the `charSet32` character set. There are __32__ characters in the set, so an index into an array of those characters would be in the range `[0,31]`. Generating a random string of `charSet32` characters is thus reduced to generating a random sequence of indices in the range `[0,31]`.
402
402
403
403
To generate the indices, `entropy-string` slices just enough bits from the array of bytes to create each index. In the example at hand, 5 bits are needed to create an index in the range `[0,31]`. `entropy-string` processes the byte array 5 bits at a time to create the indices. The first index comes from the first 5 bits of the first byte, the second index comes from the last 3 bits of the first byte combined with the first 2 bits of the second byte, and so on as the byte array is systematically sliced to form indices into the character set. And since bit shifting and addition of byte values is really efficient, this scheme is quite fast.
404
404
@@ -447,7 +447,7 @@ Fortunately you don't need to really understand how the bytes are efficiently sl
447
447
448
448
As described in [Efficiency](#Efficiency), `entropy-string` automatically generates random bytes using the `crypto` library. But you may have a need to provide your own bytes, say for deterministic testing or to use a specialized byte generator. The `random.string` function allows passing in your own bytes to create a string.
449
449
450
-
Suppose we want a string capable of 30 bits of entropy using 32 characters. We pass in 4 bytes to cover the 30 bits needed to generate 6 base32 characters:
450
+
Suppose we want a string capable of 30 bits of entropy using 32 characters. We pass in 4 bytes to cover the 30 bits needed to generate six base 32 characters:
0 commit comments