Last active
December 3, 2020 21:48
-
-
Save tech-zombie/50b3ce8f71c9adb8ba8357f32bec61b8 to your computer and use it in GitHub Desktop.
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
################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