Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.