Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-PossibleWordCombinations {
- [cmdletbinding()]
- param(
- [parameter(Mandatory=$true)]
- [String]$Word,
- [parameter(Mandatory=$true)]
- [hashtable]$Map,
- [switch]$NoCaseConsideration
- )
- $list = New-Object System.Collections.ArrayList
- $queue = New-Object System.Collections.Queue
- [void]$list.Add($word)
- $queue.Enqueue($word)
- while($queue.Count -gt 0){
- $o = $queue.Dequeue()
- for($i = 0 ; $i -lt $o.Length;$i++){
- foreach($key in $map.Keys) {
- if($o[$i] -ieq $key) {
- foreach($val in $map[$key]) {
- $newO = $o.Remove($i,1).Insert($i,$val)
- if( -not $list.Contains($newO)){
- [void]$list.Add($newO)
- }
- $queue.Enqueue($newO)
- }
- }
- }
- }
- }
- if($NoCaseConsideration) {
- $list
- } else {
- .{
- foreach($combo in $list) {
- for($i=0;$i -lt [math]::Pow(2,$combo.length);$i++){
- $res=@()
- for($j=0;$j -lt $combo.length;$j++) {
- if([bool]($i -band [math]::Pow(2,$j))){
- $res+=([string]$combo[$j]).ToUpper()
- } else {
- $res+=([string]$combo[$j]).ToLower()
- }
- }
- -join $res
- }
- }
- } | Sort-Object -Unique -CaseSensitive
- }
- }
- # Example:
- $passwords = Get-PossibleWordCombinations -Word "password" -Map @{a="@","4";o="0"}
- $passwords.Count
Advertisement
Add Comment
Please, Sign In to add comment