Skip to content

Instantly share code, notes, and snippets.

@tech-zombie
Last active December 3, 2020 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tech-zombie/50b3ce8f71c9adb8ba8357f32bec61b8 to your computer and use it in GitHub Desktop.
Save tech-zombie/50b3ce8f71c9adb8ba8357f32bec61b8 to your computer and use it in GitHub Desktop.
################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