Skip to content

Instantly share code, notes, and snippets.

@robertz
Created May 19, 2019 23:33
Show Gist options
  • Save robertz/e02ebe76e004de03b62d8137e57f6d77 to your computer and use it in GitHub Desktop.
Save robertz/e02ebe76e004de03b62d8137e57f6d77 to your computer and use it in GitHub Desktop.
param([string] $userName = "coh",
[string] $userPassword = "coh")
$ErrorActionPreference = "STOP"
function Get-Adler32 {
param(
[string] $data
)
$mod_adler = 65521
$a = 1
$b = 0
$len = $data.Length
for ($index = 0; $index -lt $len; $index++) {
$a = ($a + [byte]$data[$index]) % $mod_adler
$b = ($b + $a) % $mod_adler
}
return ($b -shl 16) -bor $a;
}
function Get-HashedPassword {
param(
[string] $UserName,
[string] $Password
)
$a32 = adler32($UserName.ToLower())
$a32hex = $a32.ToString("x8")
$a32hex = $a32hex.Substring(6, 2) + $a32hex.Substring(4, 2) + $a32hex.Substring(2, 2) + $a32hex.Substring(0, 2)
$bytes = [System.Text.Encoding]::UTF8.GetBytes($Password + $a32hex)
$digest = [System.Security.Cryptography.HashAlgorithm]::Create("SHA512").ComputeHash($bytes)
return $digest
}
$hashedPassword = Get-HashedPassword -UserName $userName -Password $userPassword
$p = ""
foreach($byte in $hashedPassword) {
$p = $p + $byte.ToString("x2");
}
Write-Host $p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment