{"id":41230680,"url":"https://github.com/jxskiss/base62","last_synced_at":"2026-01-23T00:52:17.066Z","repository":{"id":45177476,"uuid":"205154861","full_name":"jxskiss/base62","owner":"jxskiss","description":"Compact and high performace implementation of base62 algorithm for Golang.","archived":false,"fork":false,"pushed_at":"2022-08-24T00:50:00.000Z","size":19,"stargazers_count":82,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-18T16:54:11.745Z","etag":null,"topics":["base62","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jxskiss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-29T12:05:37.000Z","updated_at":"2024-06-07T11:54:56.000Z","dependencies_parsed_at":"2022-08-12T11:41:04.214Z","dependency_job_id":null,"html_url":"https://github.com/jxskiss/base62","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jxskiss/base62","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxskiss%2Fbase62","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxskiss%2Fbase62/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxskiss%2Fbase62/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxskiss%2Fbase62/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jxskiss","download_url":"https://codeload.github.com/jxskiss/base62/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxskiss%2Fbase62/sbom","scorecard":{"id":545657,"data":{"date":"2025-08-11","repo":{"name":"github.com/jxskiss/base62","commit":"f561d3edfe02e74e4e55b477f0caf37da5e69877"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":1,"reason":"Found 1/10 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/go.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/jxskiss/base62/go.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/go.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/jxskiss/base62/go.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 5 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T09:25:37.367Z","repository_id":45177476,"created_at":"2025-08-20T09:25:37.367Z","updated_at":"2025-08-20T09:25:37.367Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28676173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T20:48:19.482Z","status":"ssl_error","status_checked_at":"2026-01-22T20:48:14.968Z","response_time":144,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["base62","go","golang"],"created_at":"2026-01-23T00:52:16.414Z","updated_at":"2026-01-23T00:52:17.058Z","avatar_url":"https://github.com/jxskiss.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# base62\n\n[![GoDoc](https://img.shields.io/badge/api-Godoc-blue.svg)][godoc]\n[![Go Report Card](https://goreportcard.com/badge/github.com/jxskiss/base62)][goreport]\n[![Issues](https://img.shields.io/github/issues/jxskiss/base62.svg)][issues]\n[![GitHub release](http://img.shields.io/github/release/jxskiss/base62.svg)][release]\n[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg)][license]\n\n[godoc]: https://pkg.go.dev/github.com/jxskiss/base62\n[goreport]: https://goreportcard.com/report/github.com/jxskiss/base62\n[issues]: https://github.com/jxskiss/base62/issues\n[release]: https://github.com/jxskiss/base62/releases\n[license]: https://github.com/jxskiss/base62/blob/master/LICENSE\n\nbase62 is a correctly implemented, compact and fast implementation of `Base62` encoding/decoding algorithm.\nIt is inspired by the [java implementation by glowfall](https://github.com/glowfall/base62).\n\nThis `Base62` implementation can encode/decode both integers and bytes of arbitrary length,\nthe correctness is tested using a large number of randomly generated bytes.\n\nIt is much faster than `big.Int` based implementation and is not much slower than typical `Base64`\nimplementations. See the benchmark results below.\n\n## Why Base62\n\nIn comparison with Base64/Base32, Base62 is more friendly to human:\n\n- it contains only alpha-numerical symbols, no special characters\n- can be validated by eyes and more simple regexp\n- can be fully selected by mouse double-click in any text editors and browser address bar\n- it's compact and generates shorter strings than Base32\n- it's the most natural and unambiguous way to encode your data in human-readable form :)\n\nVariations of Base62 algorithm cann be widely used to represent authentication data in printable and\neasy-copyable form, for example to encode OAuth 2.0 `access_token` data.\n\n## Usage\n\n```go\n// Basic usage.\nEncode(src []byte) []byte\nEncodeToString(src []byte) string\nDecode(src []byte) ([]byte, error)\nDecodeString(src string) ([]byte, error)\nFormatInt(num int64) []byte\nFormatUint(num uint64) []byte\nParseInt(src []byte) (int64, error)\nParseUint(src []byte) (uint64, error)\n\n// Providing a dst buffer, you may reuse buffers to reduce memory allocation.\nEncodeToBuf(dst []byte, src []byte) []byte\nDecodeToBuf(dst []byte, src []byte) ([]byte, error)\nAppendInt(dst []byte, num int64) []byte\nAppendUint(dst []byte, num uint64) []byte\n\n// Or you may use a custom encoding alphabet.\nenc := NewEncoding(\"...my-62-byte-string-alphabet...\")\nenc.XXX()\n```\n\n## Benchmark\n\n```text\nBenchmark_Encode-12                     11654754                97.41 ns/op\nBenchmark_Decode-12                     15481666                73.60 ns/op\nBenchmark_EncodeToString-12             11950086                99.54 ns/op\nBenchmark_DecodeString-12               16301325                74.36 ns/op\n\nBenchmark_EncodeToBuf-12                13855840                84.68 ns/op\nBenchmark_DecodeToBuf-12                97695962                12.21 ns/op\n\nBenchmark_EncodeInteger-12              29119437                41.30 ns/op\nBenchmark_DecodeInteger-12             120328183                 9.917 ns/op\n\nBenchmark_Encode_BigInt-12               1000000              1048 ns/op\n\nBenchmark_Base64_EncodeToString-12      17803440                70.12 ns/op\nBenchmark_Base64_DecodeString-12        19884616                55.09 ns/op\n\nBenchmark_Base64_Encode-12              68163142                17.93 ns/op\nBenchmark_Base64_Decode-12              41990004                28.25 ns/op\n```\n\n## How it works\n\nEncoding Base64 and Base32 both are bit-aligned, 6 bits for Base64 (2^6 = 64)\nand 5 bits for Base32 (2^5 = 32), but Base62 is not bit-aligned, it's inefficient\nto do divmod operation for non-bit-aligned integers, typical Base62 implementations\nare BigInt based, which encodes input data block by block to get better performance,\n(e.g. https://github.com/keybase/saltpack/blob/master/encoding/basex).\n\n64 characters can fully represent 6 bits, but 62 characters can not, if each character\nrepresents 5 bits, that is the Base32 encoding.\n\nA naive BigInt based algorithm gives the shortest result, which is roughly like this\n(e.g. https://github.com/eknkc/basex/blob/6baac8ea8b19cc66d125286d213770fec0691867/basex.go#L46):\n\n```go\ndigits := []int{0}\nfor i := 0; i \u003c len(src); i++ {\n    carry := int(src[i])\n\n    for j := 0; j \u003c len(digits); j++ {\n        carry += digits[j] \u003c\u003c 8\n        digits[j] = carry % e.base\n        carry = carry / e.base\n    }\n\n    for carry \u003e 0 {\n        digits = append(digits, carry%e.base)\n        carry = carry / e.base\n    }\n}\n// map to encoding alphabet\n_ = digits\n```\n\nThis works but the time complexity is O(n^2) where n is the length of src. If the\ninput can be very large, the cost is unacceptable.\n\nImproved algorithm splits the input into blocks, which reduce the time complexity to\nO(kn) where k is the block size, and n is the length of src, it generates slightly\nlonger result than naive BigInt algorithm, but it is worth for the reduced time\ncomplexity. When k is n, it degrades to the naive algorithm, when k is 1, the output\nlength is twice of the input, we don't want that. 32 is chosen as the block size\nin library [saltpack/encoding/basex](https://github.com/keybase/saltpack/blob/master/encoding/basex).\n\nInspired by the [java implementation by glowfall](https://github.com/glowfall/base62),\nthis library is not BigInt based, it encodes and decodes any arbitrary bytes in O(n)\ntime complexity. Here is a brief description of the algorithm.\n\nThis library uses a variadic length encoding, for each 6 bits, if the value is in range\n[0, 62), it can be directly map to the 62 characters, if the value is 62 or 63 which\nexceeds 61, we turn to encoding just the lower 5 bits. If we find a way to recognize\nthe 5 bits pattern, then we can correctly decode it back to the source data.\n\nThe binary representation of 62 and 63 is:\n\n    62 - 0b_0011_1110\n    63 - 0b_0011_1111\n\nThey have a common mask `0b_0011_1110`, in range [0, 62), there are another two integers\nhave a similar mask `0b_0001_1110`, 30 and 31, which is:\n\n    30 - 0b_0001_1110\n    31 - 0b_0001_1111\n\nThe four integers 30, 31, 62, 63 share a common mask `0b_0001_1110`, while all other\nintegers in range [0, 64) don't share the mask, i.e. for all other integers, the\nexpression `value \u0026 0b_0001_1110 == 0b_0001_1110` evaluates to false.\n\n**This is the key point!**\n\nWe define a `compactMask` as `0b_0001_1110`.\n\nWhen encoding, for each 6 bits integer x, if `x \u0026 compactMask == compactMask` is true,\nit must be one of 30, 31, 62 or 63, we just encode the lower 5 bits, which are\n`0b_0001_1110` (30) and `0b_0001_1111` (31), we leave the 6-th bit to next byte.\n\nWhen decoding, for each encoded byte x, we check `x \u0026 compactMask == compactMask`, when\nit is false, we know that the byte represents 6 bits in the raw data, it is in range\n[0, 30) or [32, 62), else it represents 5 bits in the raw data, it is 30 or 31.\n\nThat is it, by using variadic length encoding, we successfully limit the value range\nto [0, 62), we get very compact result and a simple O(n) time complexity for encoding\nand decoding data of arbitrary length.\n\n## Compatibility\n\nThis library guarantees that it can correctly decode data encoded by itself.\n\nThe encoded result is not compatible with BigInt based algorithm,\n(e.g. [saltpack/encoding/basex, GMP and GnuPG](https://github.com/jxskiss/base62/issues/2)).\n\nThe algorithm may be ported to other languages in future (if someone does a porting,\nI'm glad to link it here :-) ).\n\n## Changelog\n\n### v1.1.0 - 2022/1/3\n\n1. Refactor the encoding code to be simpler and cleaner, as a bonus, it gives better\n   performance which is 1.5X~ faster than the old.\n2. Add a brief description of the algorithm and state the compatibility with other\n   Base62 implementations.\n\n### v1.0.0 - 2021/10/23\n\nFirst stable release, the package has been used in several small and medium projects.\n\nThis release adds new APIs which help to reuse buffers to reduce memory allocation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjxskiss%2Fbase62","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjxskiss%2Fbase62","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjxskiss%2Fbase62/lists"}