Let's talk code
PGP
My key fingerprint is 704F C50C E572 DE89 DF9F 4323 6898 544F 1DC2 3CBE
.
$
curl -s https://arindrarto.dev/0x1DC23CBE.pub.asc | gpg --show-keys --fingerprint
RNA
Coincidentally, my contact detail can also be encoded as an RNA sequence:
TGTUAGAATACGGCG TGTACGGCGACGGCG AGGATAAATGATAGG GCGAGGACGUAGGAT UAGACGGATGAGGTG
To decode it, translate it into a peptide sequence using a modified codon table where stop codons are replaced with pyrrolysine.
Base32 (modified)
decode.py
🡩
#!/usr/bin/env python3
from base64 import b32decode as b32d
def decode(value: str) -> str:
ds = (b - 128 for b in b32d(value.encode()))
return "".join(chr(d) for d in ds if d >= 32)
if __name__ == "__main__":
value = "R7R673XU4HR7JB5L6CF7TQHB6LUZH3XE6LQ7FEHU56XOJZPW"
print(decode(value))
decode.go
🡩
🞂
package main
import (
"encoding/base32"
"fmt"
"os"
)
func decode(value string) (string, error) {
ns, err := base32.StdEncoding.DecodeString(value)
if err != nil {
return "", err
}
cs := make([]rune, len(ns))
for i, n := range ns {
if n >= 160 {
cs[i] = rune(n - 128)
}
}
return string(cs), nil
}
func main() {
value := "SHR673XU4HR7JK7H56L4BYPS5HXOJ4US4GD7F5HPV3SJXZPW"
decoded, err := decode(value)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: invalid input value\n")
os.Exit(1)
}
fmt.Println(decoded)
}
decode/src/main.rs
🡩
use std::process;
use data_encoding::{BASE32, DecodeError}; // version 2.3.2
fn decode(value: impl AsRef<[u8]>) -> Result<String, DecodeError> {
let func = |x: &u8|
if *x >= 160 { Some((x - 128) as char) }
else { None };
let vref = value.as_ref();
let mut rv = String::with_capacity(vref.len() / 2);
rv.extend(BASE32.decode(vref)?.iter().filter_map(func));
Ok(rv)
}
fn main() {
let value = "Q3R673XU4HRZX5FL6LZ4BYPSQPU65ZHS4HZPJB7PV3SOL5U5";
let decoded = decode(value).unwrap_or_else(|_| {
eprintln!("Error: invalid input value");
process::exit(1);
});
println!("{}", decoded);
}
decode.js
🡩
#!/usr/bin/env node
const base32 = require('hi-base32'); // version 0.5.1
const func = (acc, n) => (
n >= 160
? `${acc}${String.fromCharCode(n - 128)}`
: acc
);
const decode = (value) => base32
.decode.asBytes(value)
.reduce(func, '');
const value = "TSFYRY7P532ODY456SV6V46A4HZOT3UQ4TZOD4XU56XOJZPW";
console.log(decode(value));
src/main/scala/decode/Main.scala
🡩
package decode
import org.apache.commons.codec.binary // "commons-codec" % "commons-codec" % "1.15"
object Main {
def decode(value: String): String = (new binary.Base32).decode(value)
.collect { case x if x >= -96 => (x + 128).toChar }
.mkString
def main(args: Array[String]): Unit = {
val value = "RPR673XUTSG6DFHD6SBKX44L4PQ6ZYOA4GGPF2PO4TZOD4XU56XOJZPW"
println(decode(value))
}
}