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

UPC-E

UPC-E (ISO/IEC 15420) of text given as its UPC-A: 11 digits, to which the check digit is added, or 12 whose last is the right check digit; the first (number system) must be 0 or 1. Check digit: weights 3, 1, 3, … from the rightmost data digit leftward, then (10 − sum mod 10) mod 10. With manufacturer digits M1–M5 (digits 2–6) and product digits P1–P5 (7–11), the six digits are, by the first rule that applies: M3 ≤ 2, M4 M5 = 00 and P1 P2 = 00 → M1 M2 P3 P4 P5 M3; M4 M5 = 00 and P1–P3 = 000 → M1 M2 M3 P4 P5 3; M5 = 0 and P1–P4 = 0000 → M1 M2 M3 M4 P5 4; M5 ≠ 0, P1–P4 = 0000 and P5 ≥ 5 → M1–M5 P5. None applying is an error, as is any other input. text: the 8 digits number system, six digits, check digit. modules: 51, no quiet zones and no add-on: 101; the six digits in sets A/B by the check digit (number system 0: 0 BBBAAA, 1 BBABAA, 2 BBAABA, 3 BBAAAB, 4 BABBAA, 5 BAABBA, 6 BAAABB, 7 BABABA, 8 BABAAB, 9 BAABAB; number system 1: A and B exchanged); 010101. Set A codes 0–9: 0001101 0011001 0010011 0111101 0100011 0110001 0101111 0111011 0110111 0001011; set C is set A with every module inverted; set B is set C reversed.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init barcode-upce --lang rust
cd barcode-upce && 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-upce.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 vectors16›
barcode-upce.cases.json
[
  {
    "args": {
      "text": "01234500006"
    }
  },
  {
    "args": {
      "text": "012345000065"
    }
  },
  {
    "args": {
      "text": "04210000526"
    }
  },
  {
    "args": {
      "text": "042100005264"
    }
  },
  {
    "args": {
      "text": "01200000003"
    }
  },
  {
    "args": {
      "text": "01230000004"
    }
  },
  {
    "args": {
      "text": "01234000005"
    }
  },
  {
    "args": {
      "text": "01234500005"
    }
  },
  {
    "args": {
      "text": "11234500006"
    }
  },
  {
    "args": {
      "text": "00000000000"
    }
  },
  {
    "args": {
      "text": "10000000007"
    }
  },
  {
    "args": {
      "text": "01234567890"
    }
  },
  {
    "args": {
      "text": "21234500006"
    }
  },
  {
    "args": {
      "text": "012345000066"
    }
  },
  {
    "args": {
      "text": "0123450000"
    }
  },
  {
    "args": {
      "text": "x1234500006"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 16 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 1,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.