{"id":16221881,"url":"https://github.com/zanaptak/binarytotextencoding","last_synced_at":"2025-03-19T11:31:14.286Z","repository":{"id":60031763,"uuid":"208633145","full_name":"zanaptak/BinaryToTextEncoding","owner":"zanaptak","description":"A binary-to-text encoder/decoder library for .NET and Fable. Provides base 16, base 32, base 46, base 64, and base 91 codecs. Supports custom character sets.","archived":false,"fork":false,"pushed_at":"2023-02-03T16:57:36.000Z","size":137,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T18:33:49.285Z","etag":null,"topics":["base16","base32","base46","base64","base91","dotnet","fable"],"latest_commit_sha":null,"homepage":"","language":"F#","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/zanaptak.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-09-15T17:49:30.000Z","updated_at":"2025-01-11T22:52:03.000Z","dependencies_parsed_at":"2023-02-18T09:16:02.947Z","dependency_job_id":null,"html_url":"https://github.com/zanaptak/BinaryToTextEncoding","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zanaptak%2FBinaryToTextEncoding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zanaptak%2FBinaryToTextEncoding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zanaptak%2FBinaryToTextEncoding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zanaptak%2FBinaryToTextEncoding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zanaptak","download_url":"https://codeload.github.com/zanaptak/BinaryToTextEncoding/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243989109,"owners_count":20379648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["base16","base32","base46","base64","base91","dotnet","fable"],"created_at":"2024-10-10T12:10:17.506Z","updated_at":"2025-03-19T11:31:13.335Z","avatar_url":"https://github.com/zanaptak.png","language":"F#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zanaptak.BinaryToTextEncoding\n\n[![GitHub](https://img.shields.io/badge/-github-gray?logo=github)](https://github.com/zanaptak/BinaryToTextEncoding) [![NuGet](https://img.shields.io/nuget/v/Zanaptak.BinaryToTextEncoding?logo=nuget)](https://www.nuget.org/packages/Zanaptak.BinaryToTextEncoding)\n\nA binary-to-text encoder/decoder library for [.NET](https://dotnet.microsoft.com/) and [Fable](https://fable.io/). Provides base 16, base 32, base 46, base 64, and base 91 codecs. Supports custom character sets.\n\n## Output example\n\nExample of a random 16-byte array (same size as a GUID) encoded in each base:\n\n- Base 16: `3A319D0D6BA340E8CFFA6E8F65236B71`\n- Base 32: `HIYZ2DLLUNAORT72N2HWKI3LOE`\n- Base 46: `G7YXHjqTF4THH7KYYxCBr4sM`\n- Base 64: `OjGdDWujQOjP+m6PZSNrcQ`\n- Base 91: `7M515sme(-[9YfN?/LIf`\n\n## Encoded bits per character\n\nThe base values in this library have been chosen because they can encode an integral number of bits as either 1 or 2 characters, making the conversion relatively efficient since groups of bits can be directly converted using lookup arrays.\n\n- Base 16: 4 bits per character\n- Base 32: 5 bits per character\n- Base 46: 5.5 bits per character (11 bits per 2 characters)\n- Base 64: 6 bits per character\n- Base 91: 6.5 bits per character (13 bits per 2 characters)\n\n## Usage\n\nAdd the [NuGet package](https://www.nuget.org/packages/Zanaptak.BinaryToTextEncoding) to your project:\n```\ndotnet add package Zanaptak.BinaryToTextEncoding\n```\n\n### C#\n```cs\nusing Zanaptak.BinaryToTextEncoding;\n\n// Default codec\nvar originalBytes = new byte[] { 1, 2, 3 };\nvar encodedString = Base32.Default.Encode(originalBytes);\nvar decodedBytes = Base32.Default.Decode(encodedString);\n\n// Custom character set\nvar customBase32 = new Base32(\"BCDFHJKMNPQRSTXZbcdfhjkmnpqrstxz\");\nvar customOriginalBytes = new byte[] { 4, 5, 6 };\nvar customEncodedString = customBase32.Encode(customOriginalBytes);\nvar customDecodedBytes = customBase32.Decode(customEncodedString);\n\n// Wrap output\nvar randomBytes = new byte[100];\nnew System.Random(12345).NextBytes(randomBytes);\nConsole.WriteLine(Base91.Default.Encode(randomBytes, 48));\n//  Output:\n//  r]g^oP{ZKd1\u003e}lC{C*P){O96SL8z%0TW,4BfEof}%!b@a#:6\n//  nN\u003cc#=}80|srYHUy6$XP}4x945a~,ItFPS;U%a^\u003cDMA]@m|#\n//  12tC]*5+BoT-4Th,oVR9wvIv;Iym\n```\n\n### F#\n```fs\nopen Zanaptak.BinaryToTextEncoding\n\n// Default codec\nlet originalBytes = [| 1uy; 2uy; 3uy |]\nlet encodedString = Base32.Default.Encode originalBytes\nlet decodedBytes = Base32.Default.Decode encodedString\n\n// Custom character set\nlet customBase32 = Base32(\"BCDFHJKMNPQRSTXZbcdfhjkmnpqrstxz\")\nlet customOriginalBytes = [| 4uy; 5uy; 6uy |]\nlet customEncodedString = customBase32.Encode customOriginalBytes\nlet customDecodedBytes = customBase32.Decode customEncodedString\n\n// Wrap output\nlet randomBytes = Array.create 100 0uy\nSystem.Random(12345).NextBytes(randomBytes)\nprintfn \"%s\" (Base91.Default.Encode(randomBytes, 48))\n//  Output:\n//  r]g^oP{ZKd1\u003e}lC{C*P){O96SL8z%0TW,4BfEof}%!b@a#:6\n//  nN\u003cc#=}80|srYHUy6$XP}4x945a~,ItFPS;U%a^\u003cDMA]@m|#\n//  12tC]*5+BoT-4Th,oVR9wvIv;Iym\n```\n\n## Notes\n\n- **Sortable**\n    - If the character set is in ASCII order, then an ASCII string sort of the encoded outputs is the same as a numeric sort of the inputs, for inputs of the same length in bytes.\n    - Note however that some of the default character sets used by different base values in this library are not in ASCII order because they are aligned with traditional implementations. A custom character set should be used if sortability is required.\n- **Case-sensitive**\n    - Encoding/decoding is case-sensitive using the exact characters in the character set. If case-insensitivity is required, it must be handled externally by converting to the case used in the character set.\n- **Padding not supported**\n    - To reduce complexity, this library does not support padding. Padding does not affect encode/decode accuracy, only string length normalization. It is not needed when exact string lengths are known or otherwise delimited (such as quoted JSON strings). If required, it must be handled externally by trimming or appending as necessary.\n\n## Built-in character sets\n\nBase16 | Description | Characters\n:--- | :--- | :---\nStandardCharacterSet | (Default) Standard hexadecimal notation, ASCII-sortable | `0123456789ABCDEF`\nConsonantsCharacterSet | Excludes numbers, vowels, and some confusable letters, ASCII-sortable | `BCDFHJKMNPQRSTXZ`\n\nBase32 | Description | Characters\n:--- | :--- | :---\nStandardCharacterSet | (Default) RFC 4648 section 6 | `ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`\nHexExtendedCharacterSet | RFC 4648 section 7, ASCII-sortable | `0123456789ABCDEFGHIJKLMNOPQRSTUV`\nConsonantsCharacterSet | Excludes numbers, vowels, and some confusable letters, ASCII-sortable | `BCDFHJKMNPQRSTXZbcdfhjkmnpqrstxz`\n\nBase46 | Description | Characters\n:--- | :--- | :---\nSortableCharacterSet | (Default) Excludes vowels and some confusable characters, ASCII-sortable | `234567BCDFGHJKMNPQRSTVW` \u003cbr /\u003e `XYZbcdfghjkmnpqrstvwxyz`\nLettersCharacterSet | Excludes numbers and some confusable letters, ASCII-sortable | `ABCDEFGHJKMNPQRSTUVWXYZ` \u003cbr /\u003e `abcdefghjkmnpqrstuvwxyz`\n\nBase64 | Description | Characters\n:--- | :--- | :---\nStandardCharacterSet | (Default) RFC 4648 section 4 | `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef` \u003cbr /\u003e `ghijklmnopqrstuvwxyz0123456789+/`\nUrlSafeCharacterSet | RFC 4648 section 5 | `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef` \u003cbr /\u003e `ghijklmnopqrstuvwxyz0123456789-_`\nUnixCryptCharacterSet | Unix crypt password hashes, ASCII-sortable | `./0123456789ABCDEFGHIJKLMNOPQRST` \u003cbr /\u003e `UVWXYZabcdefghijklmnopqrstuvwxyz`\n\nBase91 | Description | Characters\n:--- | :--- | :---\nSortableQuotableCharacterSet | (Default) Excludes `\"` `'` `\\` characters, ASCII-sortable | ```!#$%\u0026()*+,-./0123456789:;\u003c=\u003e?@A``` \u003cbr /\u003e ```BCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`a``` \u003cbr /\u003e ```bcdefghijklmnopqrstuvwxyz{\\|}~``` \u003c!-- github needs backslash for pipe --\u003e\n\nBase91Legacy | Description | Characters\n:--- | :--- | :---\nLegacyCharacterSet | (Default) Original 'basE91' character set | ```ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef``` \u003cbr /\u003e ```ghijklmnopqrstuvwxyz0123456789!#``` \u003cbr /\u003e ```$%\u0026()*+,./:;\u003c=\u003e?@[]^_`{\\|}~\"``` \u003c!-- github needs backslash for pipe --\u003e\n\n## Legacy 'basE91' compatibility\n\nThis library provides two base 91 implementations: `Base91` and `Base91Legacy`. They are not compatible; the encoded output of one cannot be decoded by the other.\n\nThe main `Base91` algorithm works like the other `BaseXX` algorithms in the library. It encodes with constant-width (each 2-character pair encodes exactly 13 bits) in big-endian order (most-significant character fist, representing the most-significant bits of the most-significant byte). The default character set is in ASCII order to preserve sortability of input, and excludes the characters `\"`, `'`, and `\\` to make it more easily quotable in programming languages.\n\n`Base91Legacy` is based on the previously existing [basE91](http://base91.sourceforge.net/) algorithm. It encodes with a variable-width mechanism (some 2-character pairs can encode 14 bits instead of 13) which can result in slightly smaller encoded strings. Each two-character pair in the output is swapped compared to the main algorithm (least-significant char of the pair first), so sorting by string is not meaningful regardless of character set. Its default character set includes the `\"` character, making it inconvenient to use in some programming languages and data formats such as JSON.\n\n\n## Benchmarks\n\nSee the [benchmark project](https://github.com/zanaptak/BinaryToTextEncoding/tree/main/benchmark).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzanaptak%2Fbinarytotextencoding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzanaptak%2Fbinarytotextencoding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzanaptak%2Fbinarytotextencoding/lists"}