Last active
September 26, 2023 12:11
-
-
Save Zazcallabah/01b2193fd89b82be7dc70ed10e75d61f to your computer and use it in GitHub Desktop.
trifid.ps1
This file contains hidden or 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
# ahnk: t | |
# scarab: s | |
# horus: r | |
param($key) | |
function makeAlpha | |
{ | |
param ($key) | |
$arr=0..25 | %{ [char]($_+65) } | |
$arrNotInKey = $arr | ?{ $key.indexof($_) -eq -1 } | |
$cleanKey = @() | |
($key -split "") | %{ | |
if(!$cleanKey.Contains($_)) | |
{ | |
$cleanKey += $_ | |
} | |
} | |
$($cleanKey; $arrNotInKey; (0..100 | %{ "." })) | ?{ $_ -ne ""} | |
} | |
function appendOnto | |
{ | |
param($head, $parts) | |
$parts | %{ "$head$_" } | |
} | |
function appendOntoMany | |
{ | |
param($heads, $parts) | |
@($heads | %{ appendOnto $_ $parts }) | |
} | |
function makelookup | |
{ | |
param($order, $alphabet) | |
$o = new-object psobject | |
$ix = 0; | |
$o | add-member -membertype noteproperty -name $order[0] -value ($alphabet[$ix]); $ix++ | |
$o | add-member -membertype noteproperty -name $order[1] -value ($alphabet[$ix]); $ix++ | |
$o | add-member -membertype noteproperty -name $order[2] -value ($alphabet[$ix]); $ix++ | |
$twos = appendOntoMany $order $order | |
$twos | %{ $nn=$_; $o | add-member -membertype noteproperty -name $nn -value ($alphabet[$ix]); $ix++ } | |
$threes = appendOntoMany $order $twos | |
$threes | %{ $nn=$_; $o | add-member -membertype noteproperty -name $nn -value ($alphabet[$ix]); $ix++ } | |
return $o | |
} | |
$words = ( | |
("trs", "r", "rst", "ts", "rts", "rss", "tr"), | |
("rsr", "rss", "tss", "t", "tt", "tss", "ts"), | |
("rst", "ts", "t", "rss", "t", "r", "rst") | |
) | |
function withOrder | |
{ | |
param($order, $alphabet) | |
$lookup = makelookup $order $alphabet | |
$reverse = new-object psobject | |
$lookup | gm -MemberType noteproperty | %{ | |
$n = $_.name | |
$v = $lookup."$n" | |
if($reverse."$v" -eq $null){ | |
$reverse | add-member -membertype noteproperty -name $v -value $n | |
} | |
} | |
0..25 | %{ | |
$a = $alphabet[$_] | |
$n = $reverse."$a" | |
write-host -nonewline "$n-$a " | |
} | |
write-host | |
write-host -nonewline ($order -join " ") | |
write-host -nonewline ":: " | |
$words | %{ | |
write-host -nonewline "`t" | |
write-host -nonewline (($_ | %{ $lookup."$_" } )-join "" ) | |
} | |
write-host | |
} | |
$orders = ( | |
("s", "r", "t"), | |
("s", "t", "r"), | |
("r", "s", "t"), | |
("r", "t", "s"), | |
("t", "s", "r"), | |
("t", "r", "s") | |
) | |
if($key -eq $null -or $key -eq "") | |
{ | |
$key = "A" | |
} | |
$alphabet = makeAlpha $key | |
write-host ($alphabet -join "") | |
$orders | %{ withOrder $_ $alphabet } |
turns out it is base 3
function toNumber
{
param($glyph)
$values = @{
"s"= 0;
"t"= 1;
"r"= 2;
}
if($glyph.length -eq 1){
return $values[$glyph]
}
$nn = $glyph -split "" | ?{$_ -ne ""}
if($nn.length -eq 3){
return $values[$nn[0]]*3*3 + $values[$nn[1]]*3 + $values[$nn[2]]
}
if($nn.length -eq 2){
return $values[$nn[0]]*3 + $values[$nn[1]]
}
}
$words = (
("trs", "r", "rst", "ts", "rts", "rss", "tr"),
("rsr", "rss", "tss", "t", "tt", "tss", "ts"),
("rst", "ts", "t", "rss", "t", "r", "rst")
)
$words | %{
$word = $_
$modded = ($word |%{
$nn= toNumber $_
return [char]($nn+64)
} ) -join ""
write-host $modded
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
outputs following for no key
which means no symbol order results in all words having values within the range of the alphabet. it is not a basic trifid cipher.