for the source see pages/dollcode on codeberg
for a version in typescript and other dollcode-related things i may write see dollcode-tools
ive tried to explain it as simply as possible but i barely know how it works
yes i know it's inefficient dont @ me
text is processed character by character, using the String.codePointAt()
function to get the decimal unicode representation. the decimal is then converted to binyary using String.toString(2)
and assembled into bytes according to utf-8 encoding. each byte is then converted into hex with parseInt(byte, 2).toString(16)
and either returned or converted into dollcode.
going backwards is a matter of converting the hex to binyary (parseInt(octet, 16).toString(2)
) and then extracting the meaningful bits. the bits are then assembled and converted into decimal which is used to generate a character. (String.fromCodePoint(parseInt(bin, 2))
)
converting hex into dollcode first converts each hex octet into deciaml (parseInt(octet, 16)
), and then takes the mod 3 of each place, and adds the respective nib
converting the dollcode to hex again first requires converting to decimal. which requires reversing the incoming dollcode so we can iterate from the greatest to least place, mapping each nib to a 1, 2, or 3, then raising the value at the current index to the appropriate power of 3.
const decimal = numbers.reduce((acc, val, ind) => { // reduce based on value place const r = val * Math.pow(3, ind) const res = r + acc return res }, 0)this is the first time ive ever seen the reduce function so thats neat
then the decimal is converted to hex using Number.toString(16)
also as a matter of credit, the code, site layout, and css are heavily referenced from noe's original work