Last active
December 8, 2017 22:12
-
-
Save bill-long/3b0af98c7e0a0504c6f7b23d9206e7fa to your computer and use it in GitHub Desktop.
Generate IOTA seed in Powershell using RNGCryptoServiceProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PowerShell script to generate IOTA seed. | |
# See https://matthewwinstonjohnson.gitbooks.io/iota-guide-and-faq/getting-started/dl-wallet/what-is-my-seed.html | |
# for seed requirements. | |
# See https://msdn.microsoft.com/en-us/library/system.security.cryptography.rngcryptoserviceprovider(v=vs.110).aspx | |
# for the reasoning behind IsFairRoll. | |
function IsFairRoll($roll, $sides) | |
{ | |
$fullSetsOfValues = [Byte]::MaxValue / $sides | |
return $roll -lt $sides * $fullSetsOfValues | |
} | |
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ9" | |
$rngCsp = New-Object System.Security.Cryptography.RNGCryptoServiceProvider | |
$totalRolls = 81 | |
$numSides = $chars.Length | |
$seed = "" | |
for ($x = 0; $x -lt $totalRolls; $x++) | |
{ | |
[byte[]]$randomNumber = @(0) | |
do | |
{ | |
$rngCsp.GetBytes($randomNumber) | |
} | |
while (-not (IsFairRoll $randomNumber[0] $numSides)) | |
$roll = $randomNumber[0] % $numSides | |
$seed += $chars[$roll] | |
} | |
$rngCsp.Dispose() | |
$seed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment