{"@attributes":{"category":"info","docName":"draft-msporny-base58-03","ipr":"trust200902","submissionType":"independent"},"front":{"title":"The Base58 Encoding Scheme","author":[{"@attributes":{"fullname":"Satoshi Nakamoto","initials":"S.N.","surname":"Nakamoto"},"organization":"Bitcoin","address":{"email":"satoshin@gmx.com"}},{"@attributes":{"fullname":"Manu Sporny","initials":"M.S.","surname":"Sporny"},"organization":"Digital Bazaar","address":{"email":"msporny@digitalbazaar.com"}}],"comment":{},"date":{"@attributes":{"month":"March","year":"2021"}},"area":"General","workgroup":"Internet Engineering Task Force","keyword":["base","encoding","base58","bitcoin"],"abstract":{"t":"\nThis document specifies the base 58 encoding scheme, including an introduction\nto the benefits of the approach, the encoding and decoding algorithm,\nalternative alphabets, and security considerations.\n      "}},"middle":{"section":[{"@attributes":{"title":"Introduction"},"t":["\nWhen trasmitting data, it can be useful to encode the data in a way that\nsurvives lower fidelity transmission mechanisms. For example, encoding data\nusing a human alphabet in a way that a person can visually confirm the\nencoded data can be more beneficial than encoding it in binary form.\nThe Base58 encoding scheme is similar to the Base64 encoding scheme in\nthat it can translate any binary data to a text string. It is different from\nBase64 in that the conversion alphabet has been carefully picked to work well\nin environments where a person, such as a developer or support technician,\nmight need to visually confirm the information with low error rates.\n      ","\nBase58 is designed with a number of usability characteristics in mind that\nBase64 does not consider. First, similar looking letters are omitted such as 0\n(zero), O (capital o), I (capital i) and l (lower case L). Doing so eliminates\nthe possibility of a human being mistaking similar characters for the wrong\ncharacter. Second, the non-alphanumeric characters + (plus), = (equals), and \/\n(slash) are omitted to make it possible to use Base58 values in all modern file\nsystems and URL schemes without the need for further system-specific encoding\nschemes. Third, by using only alphanumeric characters, easy double-click or\ndouble tap selection is possible in modern computer interfaces. Fourth, social\nmessaging systems do not line break on alphanumeric strings making it easier to\ne-mail or message Base58 values when debugging systems. Fifth, unlike Base64,\nthere is no byte padding making many Base58 values smaller (on average) or the\nsame size as Base64 values for values up to 64 bytes, and less than 2% larger\nfor larger values. Finally, Base64 has eleven encoding variations that lead to\nconfusion among developers on which variety of Base64 to use. This specification\nasserts that there is just one simple encoding mechanism for Base58, making\nimplementations and developer interactions simpler.\n      ","\nWhile Base58 does have a number of beneficial usability features, it is not\nalways a good choice for an encoding format. For example, when encoding large\namounts of data, it is 2% less efficient than base64. Base58 encoding also has\nan average worst-case algorithm complexity that is O(n^2). For these reasons,\ndevelopers might want to avoid using Base58 for encoding byte strings that\nare greater than 256 bytes in length.\n      ","\nThis document specifies the base 58 encoding scheme, including an introduction\nto the benefits of the approach, the encoding and decoding algorithm,\nalternative alphabets, and security considerations.\n      "],"section":{"@attributes":{"title":"Requirements Language"},"t":"\nThe key words \"MUST\", \"MUST NOT\", \"REQUIRED\", \"SHALL\", \"SHALL NOT\",\n\"SHOULD\", \"SHOULD NOT\", \"RECOMMENDED\", \"MAY\", and \"OPTIONAL\" in this\ndocument are to be interpreted as described in RFC 2119.\n        "}},{"@attributes":{"anchor":"alphabet","title":"The Base58 Alphabet"},"t":["\nThe Base58 alphabet consists of the following characters:\n      ","\nEach byte, interpreted as a decimal value, from 0 to 57 maps to the alphabet\nabove in the following way:\n      ","\nOther application-specific alphabets for Base58, such as the Ripple alphabet\nand the Flickr alphabet exist. Those alphabets, while valid in their own\napplication spaces, are not valid encoding formats for this specification and\nMUST NOT be used. Supporting more than one Base58 encoding alphabet would\nharm interoperability.\n      "],"figure":{"artwork":"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"},"texttable":{"@attributes":{"anchor":"alphabet-table","title":"Base58 Mapping Table"},"ttcol":["Decimal","Character","Decimal","Character"],"c":["0","1","29","W","1","2","30","X","2","3","31","Y","3","4","32","Z","4","5","33","a","5","6","34","b","6","7","35","c","7","8","36","d","8","9","37","e","9","A","38","f","10","B","39","g","11","C","40","h","12","D","41","i","13","E","42","j","14","F","43","k","15","G","44","m","16","H","45","n","17","J","46","o","18","K","47","p","19","L","48","q","20","M","49","r","21","N","50","s","22","P","51","t","23","Q","52","u","24","R","53","v","25","S","54","w","26","T","55","x","27","U","56","y","28","V","57","z"]}},{"@attributes":{"anchor":"encode","title":"The Base58 Encoding Algorithm"},"t":["\nTo encode an array of bytes to a Base58 encoded value, run the following\nalgorithm. All mathematical operations MUST be performed using integer\narithmetic. Start by initializing a 'zero_counter' to zero (0x0), an\n'encoding_flag' to zero (0x0), a 'b58_bytes' array, a 'b58_encoding' array,  and\na 'carry' value to zero (0x0). For each byte in the array of bytes and\nwhile 'carry' does not equal zero (0x0) after the first iteration:\n\n      \n    ","\nOnce the 'b58_bytes' array has been constructed, generate the final\n'b58_encoding' using the following algorithm. Set the first 'zero_counter'\nbytes in 'b58_encoding' to '1'. Then, for every byte in 'b58_array', map the\nbyte value using the Base58 alphabet in the previous section to its\ncorresponding character in 'b58_encoding'. Return 'b58_encoding' as the\nBase58 representation of the input array of bytes.\n      "]},{"@attributes":{"anchor":"decode","title":"The Base58 Decoding Algorithm"},"t":"\nTo decode a Base58 encoded array of bytes to a decoded array of bytes, run\nthe following algorithm. All mathematical operations MUST be performed using\ninteger arithmetic. Start by initializing a 'raw_bytes' array, and a\n'carry' value to zero (0x0). For each input byte in the array of input bytes:\n\n      \n      "},{"@attributes":{"anchor":"security","title":"Security Considerations"},"t":{"0":"\n      "}},{"@attributes":{"anchor":"examples","title":"Test Vectors"},"t":["\nThe following examples can be used as test vectors for the algorithms in\nthis specification:\n      ","\nThe Base58 encoded value for \"Hello World!\" is:\n        \n      ","\nThe Base58 encoded value for \"The quick brown fox jumps over the lazy dog.\" is:\n        \n      ","\nThe Base58 encoded value for 0x0000287fb4cd is:\n        \n      "]},{"@attributes":{"anchor":"Security","title":"Security Considerations"},"t":"\nThis section contains a variety of security considerations that implementers\nusing this specification are advised to consider before deploying this\ntechnology in a production setting.\n      ","section":{"@attributes":{"title":"Quadratic behaviour of base58 algorithms"},"t":["\nIn general, when converting from a source base-encoding to a target\nbase-encoding, if the target encoding is not the a numerical power of the source\nencoding, it is possible for the algorithm to degrade from linear algorithm\ncomplexity into quadratic algorithm complexity. That is, converting from base-2\n(binary) to base-32 or base-64 can be done with a worst-case algorithm\ncomplexity of O(n) time, but converting from base-2 to base-58 has a worst-case\ncomplexity of O(n^2). In short, base-58 does not work well for encoding large\nbyte values.\n        ","\nImplementers are urged to ensure that their production software imposes limits\non input size. Encoding values greater than 256 bytes in base58 is NOT\nRECOMMENDED.\n        "]}},{"@attributes":{"anchor":"Acknowledgements","title":"Acknowledgements"},"t":"\nThanks to Satoshi Nakamoto for inventing the Base58 encoding format and the\nBitcoin community for popularizing its usage.\n      "}],"rfc":{}},"back":{"0":"\n\n  "}}