Suppose I have a fingerprint to a public key like this:
b1946ac92492d2347c6235b4d2611184
If I just drop that verbatim in a doc, it’s obviously an ergonomic struggle for someone who has to verify those numbers against what they see in an app. So it should be presented as something like this:
b194 6ac9 2492 d234 7c62 35b4 d261 1184
But if we manually add a space every 4 chars, that’s embarrassing manual labor for a nerd. Self-respecting nerds make the tool do the work for us.
This code does the job:
\newcommand{\mkergo}[2][$\cdot$]{% The mandatory arg is a fingerprint; the optional arg is the delimiter between 4-char groups
\StrLen{#2}[\fplen]
\newcounter{ilpos} % internal left position
\newcounter{irpos} % internal right position
\setcounter{irpos}{4}
\whiledo{\not\value{irpos}>\fplen}{%
\setcounter{ilpos}{\value{irpos}-4}
\wlog{lpos::rpos is [\arabic{ilpos}..\arabic{irpos}]}
\StrLeft{#2}{\value{irpos}}[\left]
\wlog{left is \left}
\StrGobbleLeft{\left}{\value{ilpos}}[\segment]
\wlog{segment → \segment}
\noindent\hspace{-32pt}\segment\ifthenelse{\value{irpos}=\fplen}{}{#1}% WTF, why do we need neg hspace?!
\addtocounter{irpos}{4}
}
}
calling it looks like this:
\mkergo[\,]{b1946ac92492d2347c6235b4d2611184}
or
\newcommand{\fingerprint}{b1946ac92492d2347c6235b4d2611184}
\mkergo[\,]{\fingerprint}
It works but it’s still not something to be proud of because if the readable version of the fingerprint is needed in multiple places, that loop must run everywhere it is needed. It’s also really ugly that I had to add \hspace{-32pt} -- what the fuck for? Why is there a huge space between segments?
How can that code be improved? I tried creating a \prettyfp (short for pretty fingerprint) command and then having the loop extend that, so the \prettyfp can be used without rerunning the loop. But it’s got a logical error.. the last 4 chars just gets repeated over and over. This is the code:
\makeatletter
\newcommand{\spaceout}[2][$\cdot$]{% The mandatory arg is a fingerprint; the optional arg is the delimiter between 4-char groups
\StrLen{#2}[\fplen]
\newcounter{lpos} % internal left position
\newcounter{rpos} % internal right position
\setcounter{rpos}{4}
\whiledo{\not\value{rpos}>\fplen}{%
\setcounter{lpos}{\value{rpos}-4}
\wlog{S/O lpos::rpos is [\arabic{lpos}..\arabic{rpos}]}
\StrLeft{#2}{\value{rpos}}[\left]
\wlog{S/O left is \left}
\StrGobbleLeft{\left}{\value{lpos}}[\segment]
\wlog{S/O segment → \segment}
\g@addto@macro\prettyfp{\segment\ifthenelse{\value{irpos}=\fplen}{}{#1}}
\addtocounter{rpos}{4}
}
}
\makeatother
That was inspired by the 1st answer on this page.
What’s my problem?
How can this be improved?
GHG per passenger does not matter. It’s the net GHG that matters. If the plane is mostly empty, they will cancel the flight and shift people onto another flight.