-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexamples.exs
77 lines (64 loc) · 3.17 KB
/
examples.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#
# Compile library before running this example file:
#
# > mix compile
#
# Launching the Elixir shell from the project base directory loads EntropyString and runs
# the examples
#
# > iex --dot-iex iex.exs
#
alias EntropyString.CharSet
# --------------------------------------------------------------------------------------------------
# Id
# Predefined base 32 characters
# --------------------------------------------------------------------------------------------------
defmodule(Id, do: use(EntropyString))
IO.puts("Id: Predefined base 32 CharSet")
IO.puts(" Bits: #{Id.bits()}")
IO.puts(" Characters: #{Id.chars()}")
IO.puts(" Random ID: #{Id.string()}\n")
# --------------------------------------------------------------------------------------------------
# Hex Id
# Predefined hex characters
# --------------------------------------------------------------------------------------------------
defmodule(Hex, do: use(EntropyString, charset: :charset16))
IO.puts("Hex: Predefined hex character session id")
IO.puts(" Bits: #{Id.bits()}")
IO.puts(" Characters: #{Hex.chars()}")
IO.puts(" Random ID: #{Hex.string()}\n")
# --------------------------------------------------------------------------------------------------
# Base64 Id
# Predefined URL and file system safe characters
# --------------------------------------------------------------------------------------------------
defmodule(Base64Id, do: use(EntropyString, charset: charset64))
IO.puts("Base64Id: Predefined URL and file system safe characters")
IO.puts(" Bits: #{Id.bits()}")
IO.puts(" Characters: #{Base64Id.chars()}")
IO.puts(" Session ID: #{Base64Id.session()}\n")
# --------------------------------------------------------------------------------------------------
# Uppercase Hex Id
# Uppercase hex characters
# --------------------------------------------------------------------------------------------------
defmodule(UpperHex, do: use(EntropyString, bits: 64, charset: "0123456789ABCDEF"))
IO.puts("UpperHex: Upper case hex CharSet")
IO.puts(" Bits: #{UpperHex.bits()}")
IO.puts(" Characters: #{UpperHex.chars()}")
IO.puts(" Random ID: #{UpperHex.string()}\n")
# --------------------------------------------------------------------------------------------------
# DingoSky
# Ten million strings with a 1 in a billion chance of repeat
# --------------------------------------------------------------------------------------------------
defmodule(DingoSky, do: use(EntropyString, charset: "dingosky", total: 1.0e7, risk: 1.0e9))
IO.puts("DingoSky: Custom characters for a million IDs with a 1 in a billion chance of repeat")
IO.puts(" Bits: #{DingoSky.bits()}")
IO.puts(" Characters: #{DingoSky.chars()}")
IO.puts(" DingoSky ID: #{DingoSky.string()}\n")
# --------------------------------------------------------------------------------------------------
# Server
# 256 entropy bit token
# --------------------------------------------------------------------------------------------------
defmodule(Server, do: use(EntropyString, charset: charset64))
IO.puts("Server: 256 entropy bit token")
IO.puts(" Characters: #{Server.chars()}")
IO.puts(" Token: #{Server.token()}\n")