Created
April 8, 2022 20:58
-
-
Save McAndersDK/0c84f70d04cdee366dc26ecfb43f78e1 to your computer and use it in GitHub Desktop.
Variable Weird Behavior
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
function GenerateRainbowTable { | |
param( | |
[int]$size, | |
[char[]]$Charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
) | |
foreach($char in $Charset) { | |
if($size -eq 1) { | |
$char | |
} else { | |
GenerateRainbowTable -Size ($size -1) -charset $charset | foreach { return "$char$_"} | |
} | |
} | |
} | |
function MatchEntry { | |
param($entry,$regex,$object = $null,$index = 0,$Size) | |
foreach($entryItem in $entry) { | |
if($index -eq 0) { | |
$object = @{} | |
0..($Size-1) | foreach-object {$object.add($_,'') } | |
$object = new-object pscustomobject -Property $object | |
} | |
if ($entryItem -match "^($($regex[$index]))$") { | |
if($index -lt ($size-1)) { | |
$object.$index = $entryItem | |
MatchEntry -entry $entry -regex $regex -index ($index+1) -Size $Size -object $object | |
} else { | |
$object.$index = $entryItem | |
$object | |
} | |
} | |
} | |
} | |
$size = 2 | |
[array]$RainbowTable = GenerateRainbowTable -Size $Size -Charset 'HEFP' | |
[string[]]$Row = ('HE|LO|O+','[PLEASE]+','EP|IP|EF') | |
# I will return fine to console | |
MatchEntry -entry $RainbowTable -regex $Row -Size $size | |
# I only return the last object overwriten all entries | |
$Variable = MatchEntry -entry $RainbowTable -regex $Row -Size $size | |
$Variable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment