Re: Factor

Factor: the language, the theory, and the practice.

Scream Cipher

Sunday, September 21, 2025

Seth Larson wrote about a Scream Cipher:

You’ve probably heard of stream ciphers, but what about a scream cipher 😱? Today I learned there are more “Latin capital letter A” Unicode characters than there are letters in the English alphabet. You know what that means, it’s time to scream:

We can use bidirectional assocs to keep a single cipher data structure that efficiently maps into and out of the cipher:

CONSTANT: cipher $[
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "AÁĂẮẶẰẲẴǍÂẤẬẦẨẪÄǞȦǠẠȀÀẢȂĀĄ"
    zip >biassoc
]

: >scream ( str -- SCREAM )
    [ ch>upper cipher ?at drop ] map ;

: scream> ( SCREAM -- str )
    [ cipher ?value-at drop ] map ;

And then give it a try!

IN: scratchpad "FACTOR!" >scream .
"ẰAĂẠẪȦ!"

IN: scratchpad "ẰAĂẠẪȦ!" scream> .
"FACTOR!"

Fun!