Fun Little Cryptogram

on Monday, July 1, 2019

There’s an interesting site https://ironscripter.us/ which creates powershell based scripting challenges for practicing DevOps thinking and continual learning. It’s kind of like a kata website with a funny “Battle for the Iron Throne” feel to it.

A few days ago they posted a really small cryptogram to find a hidden message within some text. I say really small because I have a coworker that is active in crypto games and the stuff he does is mind blowing (https://op011.com/).

Ironscripter’s challenge is more light hearted and just a quick game to help you think about powershell, string manipulation, visualizing data to make it useful and so on. So, here’s my solution to the challenge.

(I think I might go back later and use a language file to try and match the text in the possible solutions; instead of trying to look through them manually.)

(Thanks to David Carroll for pointing this site out: His solution)

# $crypto = @"
# g - 2 5 R e t o p c 7 -
# h v 1 Q n e l b e d E p
# "@
$crypto = @"
P k T r 2 s z 2 * c F -
r a z 7 G u D 4 w 6 U #
g c t K 3 E @ B t 1 a Y
Q P i c % 7 0 5 Z v A e
W 6 j e P R f p m I ) H
y ^ L o o w C n b J d O
S i 9 M b e r # ) i e U
* f 2 Z 6 M S h 7 V u D
5 a ( h s v 8 e l 1 o W
Z O 7 l p K y J l D z $
- j I @ t T 2 3 R a i k
q = F & w B 6 c % H l y
"@
# using language files to automate testing the results
# https://sites.google.com/site/cryptocrackprogram/download/language-files
$dictFolder = "C:\Program Files\WindowsPowerShell\Modules\IronScriptor-20190702-Cryptogram\EnglishDict"
$dictFiles = dir -Path $dictFolder -Recurse *.* -File
$allwords = $dictFiles |% { Get-Content -Path $_.FullName }
function Test-DictionaryWords ([string] $Possible) {
$Possible = $Possible -replace "-", ""
$Possible = $Possible.ToUpper()
foreach($word in $allwords) {
if($Possible.StartsWith($word)) {
if($Possible.Length -eq $word.Length) {
return $true
}
$newPossible = $Possible.Substring($word.Length)
$results = Test-DictionaryWords -Possible $newPossible
if($results -eq $true) {
return $true
}
}
}
return $false
}
$crypto = $crypto -replace " ", ""
$crypto = $crypto -replace "`r", ""
$crypto = $crypto -replace "`n", ""
$cryptolen = $crypto.Length
$results = @()
for($x = 1; $x -lt 20; $x++) {
$props = [PSCustomObject] @{}
for($y = 1; $y -lt 20; $y++) {
$plaintext = ""
for($j = 0; ((($x + $y) * $j) + $x) -le $cryptolen; $j++) {
$cx = (($x + $y) * $j) + $x
$plaintext += $crypto[$cx - 1]
$cy = (($x + $y) * $j) + $x + $y
if($cy -le $cryptolen) {
$plaintext += $crypto[$cy - 1]
}
}
$props = [PSCustomObject] @{
X = $x
Y = $y
PlainText = $plaintext
PlainTextL = $plaintext.ToLower()
DictionaryMatch = Test-DictionaryWords -Possible $plaintext
}
$results += @($props)
if($props.DictionaryMatch) {
$props | ft X, Y, PlainText -AutoSize
break
}
}
if($props.DictionaryMatch) {
break
}
}
#$results | ft X, Y, PlainTextL -AutoSize
#$results |? { $_.plaintext -match "-" } | ft X, Y, PlainText -AutoSize
#$results |? { $_.plaintextl -notmatch "[^a-zA-z\-]" } | ft X, Y, PlainTextL -AutoSize
#$results |? { $_.X -eq 1 -and $_.Y -eq 12 }

0 comments:

Post a Comment


Creative Commons License
This site uses Alex Gorbatchev's SyntaxHighlighter, and hosted by herdingcode.com's Jon Galloway.