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

The RNA sequence TGTUAGAATACGGCG TGTACGGCGACGGCG AGGATAAATGATAGG GCGAGGACGUAGGAT UAGACGGATGAGGTG encodes my contact detail. 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 = "TXRYRAHP52PPJYPD6TAOD4XJ52COJ4XBTHZPJAHPV2JOJZPW"
            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 := "QXR673UMQP2JZYPD6TAOD4XJ53SPFG7B6KM7J35OT3SOL5UB"
            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 = "R7R673XU4HRZF5GA4HZIZHE35HXOJ4XB6L2JL35OSLSOL5UZ";
            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 = "S3R673XUT6LJZYPD6TAOD4U55HXOJCU66LQ7F5HPV3SOL5UM";
        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 = "QTR673XU4HR7JQEM4HZIL2POQLSPFAXB6L2O7DNO4TS7NG4D"
            println(decode(value))
          }
        }