Skip to content

Instantly share code, notes, and snippets.

@bill-long
Last active December 8, 2017 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/3b0af98c7e0a0504c6f7b23d9206e7fa to your computer and use it in GitHub Desktop.
Save bill-long/3b0af98c7e0a0504c6f7b23d9206e7fa to your computer and use it in GitHub Desktop.
Generate IOTA seed in Powershell using RNGCryptoServiceProvider
# 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