Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
################PART 1################
(((Get-Content .\input.txt -raw) -replace " ",",") -replace "-",",") -replace ":","" > input.csv
$header ="min","max","char","password"
$list = import-csv .\input.csv -header $header
$total = 0
foreach ($line in $list)
{
$count = ($line.password.ToCharArray() | Where-Object {$_ -eq $line.char} | Measure-Object).count
#$count
if ($count -gt $line.max){}
elseif ($count -lt $line.min){}
else{$total++}
}
$total
###################Part2####################
(((Get-Content .\input.txt -raw) -replace " ",",") -replace "-",",") -replace ":","" > input.csv
$header ="pos1","pos2","char","password"
$list = import-csv .\input.csv -header $header
$total = 0
foreach ($line in $list)
{
$check1 = $line.password.substring([int]$line.pos1 -1, 1)
$check2 = $line.password.Substring([int]$line.pos2 -1, 1)
if ($check1 -eq $line.char)
{
if ($check2 -eq $line.char){}
else {$total++}
}
elseif ($check2 -eq $line.char)
{ $total++ }
}
$total
#####alternative way to convert to csv
(Get-Content .\input.txt) -replace '[- :]+', ',' | ConvertFrom-Csv -Header pos1, pos2, char, password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment