Skip to content

Instantly share code, notes, and snippets.

@Zazcallabah
Last active September 26, 2023 12:11
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 Zazcallabah/01b2193fd89b82be7dc70ed10e75d61f to your computer and use it in GitHub Desktop.
Save Zazcallabah/01b2193fd89b82be7dc70ed10e75d61f to your computer and use it in GitHub Desktop.
trifid.ps1
# 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 }
@Zazcallabah
Copy link
Author

outputs following for no key

ABCDEFGHIJKLMNOPQRSTUVWXYZ.....................................................................................................
s r t::         .AWI.UJ VU.BK.I WIBUBAW
s t r::         .B.F..H ..UAGUF .FA.AB.
r s t::         .QJSPI  OP.BK.J QJBPBQ
r t s::         WSHQTF  RT.AG.H SHATAS
t s r::         SB.D..E ..PCPD  .D.B.
t r s::         QA.EW.D ..TCTE  .E.A.

which means no symbol order results in all words having values within the range of the alphabet. it is not a basic trifid cipher.

@Zazcallabah
Copy link
Author

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