Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
barcode / barcode-code128OpenRuns on Liberas

Code 128

Code 128 (ISO/IEC 15417) of text: 1 to 80 characters, each U+0000 to U+007F; anything else is an error. No FNC1–4, no GS1. Sets: A holds 0–95 (value c − 32 for 32–95, c + 64 for 0–31), B holds 32–127 (value c − 32), C a pair of digits (value 0–99). Symbols are chosen by fewest symbols, exactly so: cost(i, S) is the fewest symbol characters that encode text[i..] from set S (cost at the end is 0) over these moves, in this order: (1) direct: one character of S (A, B) or two digits (C), 1 symbol, staying in S; (2) shift, from A or B, for a character of the other of the two: Shift (98) then its value there, 2 symbols, staying in S; (3) for T in the order B, C, A, T ≠ S: Code T (to C 99, to B 100, to A 101) then a direct move in T, 2 symbols, now in T. The start set is the first of B, C, A with the least cost(0, S) (Start A 103, B 104, C 105); then at each position the first move in that order that achieves cost(i, S) is taken. Check symbol: (start value + Σ k · value of the k-th symbol after the start) mod 103. modules: start, the symbols, check, stop, each symbol its six bar/space widths (11 modules) from the standard's table, the stop 2331112 (13 modules); no quiet zones. text echoes the input.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init barcode-code128 --lang rust
cd barcode-code128 && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)21 lines›
barcode-code128.wit
package root:component;

world root {
  import liberas:barcode/types@0.1.0;

  export liberas:barcode/linear-encode@0.1.0;
}
package liberas:barcode@0.1.0 {
  interface types {
    record linear {
      text: string,
      modules: string,
    }
  }
  interface linear-encode {
    use types.{linear};

    encode: func(text: string) -> result<linear, string>;
  }
}
Test vectors18›
barcode-code128.cases.json
[
  {
    "args": {
      "text": "ABC"
    }
  },
  {
    "args": {
      "text": "12345"
    }
  },
  {
    "args": {
      "text": "123456"
    }
  },
  {
    "args": {
      "text": "1"
    }
  },
  {
    "args": {
      "text": "12"
    }
  },
  {
    "args": {
      "text": "abc123456def"
    }
  },
  {
    "args": {
      "text": "Hello, World!"
    }
  },
  {
    "args": {
      "text": "\u0001\u001fab"
    }
  },
  {
    "args": {
      "text": "a\tb\tc"
    }
  },
  {
    "args": {
      "text": "AB12cd\u000534567890"
    }
  },
  {
    "args": {
      "text": "~ `"
    }
  },
  {
    "args": {
      "text": "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
    }
  },
  {
    "args": {
      "text": "\u0001&Kp\u0016;`\u0006+Pu\u001b@e\u000b0Uz Ej\u00105Z%Jo\u0015:_\u0005*Ot\u001a?d\n/Ty\u001fDi\u000f4Y~$In\u00149^\u0004)Ns\u0019>c\t.Sx\u001eCh\u000e3X}#Hm\u00138]\u0003"
    }
  },
  {
    "args": {
      "text": "PJJ123C"
    }
  },
  {
    "args": {
      "text": ""
    }
  },
  {
    "args": {
      "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    }
  },
  {
    "args": {
      "text": "é"
    }
  },
  {
    "args": {
      "text": "한글"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 18 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 2,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.