<?xml version='1.0' encoding='utf-8'?>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" version="3" category="info" consensus="true" docName="draft-faltstrom-base45-12" indexInclude="true" ipr="trust200902" number="9285" prepTime="2022-08-09T15:11:15" scripts="Common,Latin" sortRefs="true" submissionType="IETF" symRefs="true" tocDepth="3" tocInclude="true" xml:lang="en">
  <link href="https://datatracker.ietf.org/doc/draft-faltstrom-base45-12" rel="prev"/>
  <link href="https://dx.doi.org/10.17487/rfc9285" rel="alternate"/>
  <link href="urn:issn:2070-1721" rel="alternate"/>
  <front>
    <title abbrev="Base45">The Base45 Data Encoding</title>
    <seriesInfo name="RFC" value="9285" stream="IETF"/>
    <author fullname="Patrik Fältström" initials="P." surname="Fältström">
      <organization showOnFrontPage="true">Netnod</organization>
      <address>
        <email>paf@netnod.se</email>
      </address>
    </author>
    <author fullname="Fredrik Ljunggren" initials="F." surname="Ljunggren">
      <organization showOnFrontPage="true">Kirei</organization>
      <address>
        <email>fredrik@kirei.se</email>
      </address>
    </author>
    <author fullname="Dirk-Willem van Gulik" initials="D.W." surname="van Gulik">
      <organization showOnFrontPage="true">Webweaving</organization>
      <address>
        <email>dirkx@webweaving.org</email>
      </address>
    </author>
    <date month="08" year="2022"/>
    <keyword>BASE45</keyword>
    <abstract pn="section-abstract">
      <t indent="0" pn="section-abstract-1">
	This document describes the Base45 encoding scheme, which is
	built upon the Base64, Base32, and Base16 encoding schemes.
      </t>
    </abstract>
    <boilerplate>
      <section anchor="status-of-memo" numbered="false" removeInRFC="false" toc="exclude" pn="section-boilerplate.1">
        <name slugifiedName="name-status-of-this-memo">Status of This Memo</name>
        <t indent="0" pn="section-boilerplate.1-1">
            This document is not an Internet Standards Track specification; it is
            published for informational purposes.  
        </t>
        <t indent="0" pn="section-boilerplate.1-2">
            This document is a product of the Internet Engineering Task Force
            (IETF).  It represents the consensus of the IETF community.  It has
            received public review and has been approved for publication by the
            Internet Engineering Steering Group (IESG).  Not all documents
            approved by the IESG are candidates for any level of Internet
            Standard; see Section 2 of RFC 7841. 
        </t>
        <t indent="0" pn="section-boilerplate.1-3">
            Information about the current status of this document, any
            errata, and how to provide feedback on it may be obtained at
            <eref target="https://www.rfc-editor.org/info/rfc9285" brackets="none"/>.
        </t>
      </section>
      <section anchor="copyright" numbered="false" removeInRFC="false" toc="exclude" pn="section-boilerplate.2">
        <name slugifiedName="name-copyright-notice">Copyright Notice</name>
        <t indent="0" pn="section-boilerplate.2-1">
            Copyright (c) 2022 IETF Trust and the persons identified as the
            document authors. All rights reserved.
        </t>
        <t indent="0" pn="section-boilerplate.2-2">
            This document is subject to BCP 78 and the IETF Trust's Legal
            Provisions Relating to IETF Documents
            (<eref target="https://trustee.ietf.org/license-info" brackets="none"/>) in effect on the date of
            publication of this document. Please review these documents
            carefully, as they describe your rights and restrictions with
            respect to this document. Code Components extracted from this
            document must include Revised BSD License text as described in
            Section 4.e of the Trust Legal Provisions and are provided without
            warranty as described in the Revised BSD License.
        </t>
      </section>
    </boilerplate>
    <toc>
      <section anchor="toc" numbered="false" removeInRFC="false" toc="exclude" pn="section-toc.1">
        <name slugifiedName="name-table-of-contents">Table of Contents</name>
        <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1">
          <li pn="section-toc.1-1.1">
            <t indent="0" keepWithNext="true" pn="section-toc.1-1.1.1"><xref derivedContent="1" format="counter" sectionFormat="of" target="section-1"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-introduction">Introduction</xref></t>
          </li>
          <li pn="section-toc.1-1.2">
            <t indent="0" keepWithNext="true" pn="section-toc.1-1.2.1"><xref derivedContent="2" format="counter" sectionFormat="of" target="section-2"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-conventions-used-in-this-do">Conventions Used in This Document</xref></t>
          </li>
          <li pn="section-toc.1-1.3">
            <t indent="0" keepWithNext="true" pn="section-toc.1-1.3.1"><xref derivedContent="3" format="counter" sectionFormat="of" target="section-3"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-interpretation-of-encoded-d">Interpretation of Encoded Data</xref></t>
          </li>
          <li pn="section-toc.1-1.4">
            <t indent="0" pn="section-toc.1-1.4.1"><xref derivedContent="4" format="counter" sectionFormat="of" target="section-4"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-the-base45-encoding">The Base45 Encoding</xref></t>
            <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.4.2">
              <li pn="section-toc.1-1.4.2.1">
                <t indent="0" pn="section-toc.1-1.4.2.1.1"><xref derivedContent="4.1" format="counter" sectionFormat="of" target="section-4.1"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-when-to-use-and-not-use-bas">When to Use and Not Use Base45</xref></t>
              </li>
              <li pn="section-toc.1-1.4.2.2">
                <t indent="0" pn="section-toc.1-1.4.2.2.1"><xref derivedContent="4.2" format="counter" sectionFormat="of" target="section-4.2"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-the-alphabet-used-in-base45">The Alphabet Used in Base45</xref></t>
              </li>
              <li pn="section-toc.1-1.4.2.3">
                <t indent="0" pn="section-toc.1-1.4.2.3.1"><xref derivedContent="4.3" format="counter" sectionFormat="of" target="section-4.3"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-encoding-examples">Encoding Examples</xref></t>
              </li>
              <li pn="section-toc.1-1.4.2.4">
                <t indent="0" pn="section-toc.1-1.4.2.4.1"><xref derivedContent="4.4" format="counter" sectionFormat="of" target="section-4.4"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-decoding-example">Decoding Example</xref></t>
              </li>
            </ul>
          </li>
          <li pn="section-toc.1-1.5">
            <t indent="0" pn="section-toc.1-1.5.1"><xref derivedContent="5" format="counter" sectionFormat="of" target="section-5"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-iana-considerations">IANA Considerations</xref></t>
          </li>
          <li pn="section-toc.1-1.6">
            <t indent="0" pn="section-toc.1-1.6.1"><xref derivedContent="6" format="counter" sectionFormat="of" target="section-6"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-security-considerations">Security Considerations</xref></t>
          </li>
          <li pn="section-toc.1-1.7">
            <t indent="0" pn="section-toc.1-1.7.1"><xref derivedContent="7" format="counter" sectionFormat="of" target="section-7"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-normative-references">Normative References</xref></t>
          </li>
          <li pn="section-toc.1-1.8">
            <t indent="0" pn="section-toc.1-1.8.1"><xref derivedContent="" format="none" sectionFormat="of" target="section-appendix.a"/><xref derivedContent="" format="title" sectionFormat="of" target="name-acknowledgements">Acknowledgements</xref></t>
          </li>
          <li pn="section-toc.1-1.9">
            <t indent="0" pn="section-toc.1-1.9.1"><xref derivedContent="" format="none" sectionFormat="of" target="section-appendix.b"/><xref derivedContent="" format="title" sectionFormat="of" target="name-authors-addresses">Authors' Addresses</xref></t>
          </li>
        </ul>
      </section>
    </toc>
  </front>
  <middle>
    <section anchor="intro" numbered="true" toc="include" removeInRFC="false" pn="section-1">
      <name slugifiedName="name-introduction">Introduction</name>
      <t indent="0" pn="section-1-1">
	A QR code is used to encode text as a graphical
	image. Depending on the characters used in the text, various
	encoding options for a QR code exist, e.g., Numeric,
	Alphanumeric, and Byte mode.  Even in Byte mode, a typical
	QR code reader tries to interpret a byte sequence as text encoded in UTF-8
	or ISO/IEC 8859-1. Thus, QR codes cannot be used
	to encode arbitrary binary data directly. Such data has to be
	converted into an appropriate text before that text could be
	encoded as a QR code.  Compared to already established Base64,
	Base32, and Base16 encoding schemes that are described in
	<xref target="RFC4648" format="default" sectionFormat="of" derivedContent="RFC4648"/>, the Base45 scheme
	described in this document offers a more compact QR code
	encoding.
      </t>
      <t indent="0" pn="section-1-2">
	One important difference from those others and Base45 is the
	key table and that the padding with '=' is not required.
      </t>
    </section>
    <section numbered="true" toc="include" removeInRFC="false" pn="section-2">
      <name slugifiedName="name-conventions-used-in-this-do">Conventions Used in This Document</name>
      <t indent="0" pn="section-2-1">
    The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>", "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>", "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
    "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are to be interpreted as
    described in BCP 14 <xref target="RFC2119" format="default" sectionFormat="of" derivedContent="RFC2119"/> <xref target="RFC8174" format="default" sectionFormat="of" derivedContent="RFC8174"/> 
    when, and only when, they appear in all capitals, as shown here.
      </t>
    </section>
    <section numbered="true" toc="include" removeInRFC="false" pn="section-3">
      <name slugifiedName="name-interpretation-of-encoded-d">Interpretation of Encoded Data</name>
      <t indent="0" pn="section-3-1">
	Encoded data is to be interpreted as described in <xref target="RFC4648" format="default" sectionFormat="of" derivedContent="RFC4648"/> with the exception that a
	different alphabet is selected.
      </t>
    </section>
    <section numbered="true" toc="include" removeInRFC="false" pn="section-4">
      <name slugifiedName="name-the-base45-encoding">The Base45 Encoding</name>
      <t indent="0" pn="section-4-1">
	QR codes have a limited ability to store binary data. In
	practice, binary data have to be encoded in characters
	according to one of the modes already defined in the standard
	for QR codes. The easiest mode to use in called Alphanumeric
	mode (see Section 7.3.4 and Table 2 of <xref target="ISO18004" format="default" sectionFormat="of" derivedContent="ISO18004"/>.  Unfortunately
	Alphanumeric mode uses 45 different characters which implies
	neither Base32 nor Base64 are very effective encodings.
      </t>
      <t indent="0" pn="section-4-2">
	A 45-character subset of US-ASCII is used; the 45 characters
	usable in a QR code in Alphanumeric mode (see Section 7.3.4
	and Table 2 of <xref target="ISO18004" format="default" sectionFormat="of" derivedContent="ISO18004"/>). Base45 encodes 2 bytes in 3 characters,
	compared to Base64, which encodes 3 bytes in 4 characters.
      </t>
      <t indent="0" pn="section-4-3">
	For encoding, two bytes [a, b] <bcp14>MUST</bcp14> be
	interpreted as a number n in base 256, i.e. as an unsigned
	integer over 16 bits so that the number n = (a * 256) + b.
      </t>
      <t indent="0" pn="section-4-4">
	This number n is converted to base 45 [c, d, e] so that n = c
	+ (d * 45) + (e * 45 * 45). Note the order of c, d and e which
	are chosen so that the left-most [c] is the least significant.
      </t>
      <t indent="0" pn="section-4-5">
	The values c, d, and e are then looked up in <xref target="table1" format="default" sectionFormat="of" derivedContent="Table 1"/> to produce a three character string. The
	process is reversed when decoding.
      </t>
      <t indent="0" pn="section-4-6">
	For encoding a single byte [a], it <bcp14>MUST</bcp14> be
	interpreted as a base 256 number, i.e. as an unsigned integer
	over 8 bits. That integer <bcp14>MUST</bcp14> be converted to
	base 45 [c d] so that a = c + (45 * d). The values c and d are
	then looked up in <xref target="table1" format="default" sectionFormat="of" derivedContent="Table 1"/> to produce a
	two-character string.
      </t>
      <t indent="0" pn="section-4-7">
	A byte string [a b c d ... x y z] with arbitrary content and
	arbitrary length <bcp14>MUST</bcp14> be encoded as follows:
	From left to right pairs of bytes <bcp14>MUST</bcp14> be
	encoded as described above. If the number of bytes is even,
	then the encoded form is a string with a length that is evenly
	divisible by 3. If the number of bytes is odd, then the last
	(rightmost) byte <bcp14>MUST</bcp14> be encoded on two
	characters as described above.
      </t>
      <t indent="0" pn="section-4-8">
	For decoding a Base45 encoded string the inverse operations
	are performed.
      </t>
      <section numbered="true" toc="include" removeInRFC="false" pn="section-4.1">
        <name slugifiedName="name-when-to-use-and-not-use-bas">When to Use and Not Use Base45</name>
        <t indent="0" pn="section-4.1-1">
	  If binary data is to be stored in a QR code, the suggested
	  mechanism is to use the Alphanumeric mode that uses 11 bits
	  for 2 characters as defined in Section 7.3.4 of <xref target="ISO18004" format="default" sectionFormat="of" derivedContent="ISO18004"/>. The Extended Channel Interpretation (ECI) mode
	  indicator for this encoding is 0010.
        </t>
        <t indent="0" pn="section-4.1-2">
	  On the other hand if the data is to be sent via some other
	  transport, a transport encoding suitable for that transport
	  should be used instead of Base45. For example, it is not
	  recommended to first encode data in Base45 and then encode
	  the resulting string in Base64 if the data is to be sent via
	  email. Instead, the Base45 encoding should be removed, and
	  the data itself should be encoded in Base64.
        </t>
      </section>
      <section numbered="true" toc="include" removeInRFC="false" pn="section-4.2">
        <name slugifiedName="name-the-alphabet-used-in-base45">The Alphabet Used in Base45</name>
        <t indent="0" pn="section-4.2-1">
	  The Alphanumeric mode is defined to use 45 characters as specified
	  in this alphabet.
        </t>
        <table anchor="table1" align="center" pn="table-1">
          <name slugifiedName="name-the-base45-alphabet">The Base45 Alphabet</name>
          <thead>
            <tr>
              <th align="right" colspan="1" rowspan="1">Value</th>
              <th align="left" colspan="1" rowspan="1">Encoding</th>
              <th align="right" colspan="1" rowspan="1">Value</th>
              <th align="left" colspan="1" rowspan="1">Encoding</th>
              <th align="right" colspan="1" rowspan="1">Value</th>
              <th align="left" colspan="1" rowspan="1">Encoding</th>
              <th align="right" colspan="1" rowspan="1">Value</th>
              <th align="left" colspan="1" rowspan="1">Encoding</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td align="right" colspan="1" rowspan="1">00</td>
              <td align="left" colspan="1" rowspan="1">0</td>
              <td align="right" colspan="1" rowspan="1">12</td>
              <td align="left" colspan="1" rowspan="1">C</td>
              <td align="right" colspan="1" rowspan="1">24</td>
              <td align="left" colspan="1" rowspan="1">O</td>
              <td align="right" colspan="1" rowspan="1">36</td>
              <td align="left" colspan="1" rowspan="1">Space</td>
            </tr>
            <tr>
              <td align="right" colspan="1" rowspan="1">01</td>
              <td align="left" colspan="1" rowspan="1">1</td>
              <td align="right" colspan="1" rowspan="1">13</td>
              <td align="left" colspan="1" rowspan="1">D</td>
              <td align="right" colspan="1" rowspan="1">25</td>
              <td align="left" colspan="1" rowspan="1">P</td>
              <td align="right" colspan="1" rowspan="1">37</td>
              <td align="left" colspan="1" rowspan="1">$</td>
            </tr>
            <tr>
              <td align="right" colspan="1" rowspan="1">02</td>
              <td align="left" colspan="1" rowspan="1">2</td>
              <td align="right" colspan="1" rowspan="1">14</td>
              <td align="left" colspan="1" rowspan="1">E</td>
              <td align="right" colspan="1" rowspan="1">26</td>
              <td align="left" colspan="1" rowspan="1">Q</td>
              <td align="right" colspan="1" rowspan="1">38</td>
              <td align="left" colspan="1" rowspan="1">%</td>
            </tr>
            <tr>
              <td align="right" colspan="1" rowspan="1">03</td>
              <td align="left" colspan="1" rowspan="1">3</td>
              <td align="right" colspan="1" rowspan="1">15</td>
              <td align="left" colspan="1" rowspan="1">F</td>
              <td align="right" colspan="1" rowspan="1">27</td>
              <td align="left" colspan="1" rowspan="1">R</td>
              <td align="right" colspan="1" rowspan="1">39</td>
              <td align="left" colspan="1" rowspan="1">*</td>
            </tr>
            <tr>
              <td align="right" colspan="1" rowspan="1">04</td>
              <td align="left" colspan="1" rowspan="1">4</td>
              <td align="right" colspan="1" rowspan="1">16</td>
              <td align="left" colspan="1" rowspan="1">G</td>
              <td align="right" colspan="1" rowspan="1">28</td>
              <td align="left" colspan="1" rowspan="1">S</td>
              <td align="right" colspan="1" rowspan="1">40</td>
              <td align="left" colspan="1" rowspan="1">+</td>
            </tr>
            <tr>
              <td align="right" colspan="1" rowspan="1">05</td>
              <td align="left" colspan="1" rowspan="1">5</td>
              <td align="right" colspan="1" rowspan="1">17</td>
              <td align="left" colspan="1" rowspan="1">H</td>
              <td align="right" colspan="1" rowspan="1">29</td>
              <td align="left" colspan="1" rowspan="1">T</td>
              <td align="right" colspan="1" rowspan="1">41</td>
              <td align="left" colspan="1" rowspan="1">-</td>
            </tr>
            <tr>
              <td align="right" colspan="1" rowspan="1">06</td>
              <td align="left" colspan="1" rowspan="1">6</td>
              <td align="right" colspan="1" rowspan="1">18</td>
              <td align="left" colspan="1" rowspan="1">I</td>
              <td align="right" colspan="1" rowspan="1">30</td>
              <td align="left" colspan="1" rowspan="1">U</td>
              <td align="right" colspan="1" rowspan="1">42</td>
              <td align="left" colspan="1" rowspan="1">.</td>
            </tr>
            <tr>
              <td align="right" colspan="1" rowspan="1">07</td>
              <td align="left" colspan="1" rowspan="1">7</td>
              <td align="right" colspan="1" rowspan="1">19</td>
              <td align="left" colspan="1" rowspan="1">J</td>
              <td align="right" colspan="1" rowspan="1">31</td>
              <td align="left" colspan="1" rowspan="1">V</td>
              <td align="right" colspan="1" rowspan="1">43</td>
              <td align="left" colspan="1" rowspan="1">/</td>
            </tr>
            <tr>
              <td align="right" colspan="1" rowspan="1">08</td>
              <td align="left" colspan="1" rowspan="1">8</td>
              <td align="right" colspan="1" rowspan="1">20</td>
              <td align="left" colspan="1" rowspan="1">K</td>
              <td align="right" colspan="1" rowspan="1">32</td>
              <td align="left" colspan="1" rowspan="1">W</td>
              <td align="right" colspan="1" rowspan="1">44</td>
              <td align="left" colspan="1" rowspan="1">:</td>
            </tr>
            <tr>
              <td align="right" colspan="1" rowspan="1">09</td>
              <td align="left" colspan="1" rowspan="1">9</td>
              <td align="right" colspan="1" rowspan="1">21</td>
              <td align="left" colspan="1" rowspan="1">L</td>
              <td align="right" colspan="1" rowspan="1">33</td>
              <td align="left" colspan="1" rowspan="1">X</td>
              <td align="left" colspan="1" rowspan="1"/>
              <td align="left" colspan="1" rowspan="1"/>
            </tr>
            <tr>
              <td align="right" colspan="1" rowspan="1">10</td>
              <td align="left" colspan="1" rowspan="1">A</td>
              <td align="right" colspan="1" rowspan="1">22</td>
              <td align="left" colspan="1" rowspan="1">M</td>
              <td align="right" colspan="1" rowspan="1">34</td>
              <td align="left" colspan="1" rowspan="1">Y</td>
              <td align="left" colspan="1" rowspan="1"/>
              <td align="left" colspan="1" rowspan="1"/>
            </tr>
            <tr>
              <td align="right" colspan="1" rowspan="1">11</td>
              <td align="left" colspan="1" rowspan="1">B</td>
              <td align="right" colspan="1" rowspan="1">23</td>
              <td align="left" colspan="1" rowspan="1">N</td>
              <td align="right" colspan="1" rowspan="1">35</td>
              <td align="left" colspan="1" rowspan="1">Z</td>
              <td align="left" colspan="1" rowspan="1"/>
              <td align="left" colspan="1" rowspan="1"/>
            </tr>
          </tbody>
        </table>
      </section>
      <section numbered="true" toc="include" removeInRFC="false" pn="section-4.3">
        <name slugifiedName="name-encoding-examples">Encoding Examples</name>
        <t indent="0" pn="section-4.3-1">
	  It should be noted that although the examples are all text,
	  Base45 is an encoding for binary data where each octet can
	  have any value 0-255.
        </t>
        <t indent="0" pn="section-4.3-2">Encoding example 1:</t>
        <t indent="3" pn="section-4.3-3">
  The string "AB" is the byte sequence [[65 66]].
  
  If we look at all 16 bits, we get 65 * 256 + 66 = 16706.
  
  16706 equals 11 + (11 * 45) + (8 * 45 * 45), so the sequence in base 45 is [11 11 8].
  
  Referring to <xref target="table1" format="default" sectionFormat="of" derivedContent="Table 1"/>,  we get the encoded string "BB8".
</t>
        <table align="center" pn="table-2">
          <name slugifiedName="name-example-1-in-detail">Example 1 in Detail</name>
          <tbody>
            <tr>
              <td align="left" colspan="1" rowspan="1">AB</td>
              <td align="left" colspan="1" rowspan="1">Initial string</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[[65 66]]</td>
              <td align="left" colspan="1" rowspan="1">Decimal value</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[16706]</td>
              <td align="left" colspan="1" rowspan="1">Value in base 16</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[11 11 8]</td>
              <td align="left" colspan="1" rowspan="1">Value in base 45</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">BB8</td>
              <td align="left" colspan="1" rowspan="1">Encoded string</td>
            </tr>
          </tbody>
        </table>
        <t indent="0" pn="section-4.3-5">Encoding example 2:</t>
        <t indent="3" pn="section-4.3-6">
  The string "Hello!!" as ASCII is the byte sequence [[72 101] [108 108] [111 33] [33]].
  
  If we look at this 16 bits at a time, we get [18533 27756 28449 33]. Note the 33 for the last byte.
  
     When looking at the values in base 45, we get [[38 6 9] [36 31 13] [9 2 14] [33 0]], where the last byte is represented by two values.
  
     The resulting string "%69 VD92EX0" is created by looking up these values in <xref target="table1" format="default" sectionFormat="of" derivedContent="Table 1"/>.  It should be noted it includes a space.
</t>
        <table align="center" pn="table-3">
          <name slugifiedName="name-example-2-in-detail">Example 2 in Detail</name>
          <tbody>
            <tr>
              <td align="left" colspan="1" rowspan="1">Hello!!</td>
              <td align="left" colspan="1" rowspan="1">Initial string</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[[72 101] [108 108] [111 33] [33]]</td>
              <td align="left" colspan="1" rowspan="1">Decimal value</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[18533 27756 28449 33]</td>
              <td align="left" colspan="1" rowspan="1">Value in base 16</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[[38 6 9] [36 31 13] [9 2 14] [33 0]]</td>
              <td align="left" colspan="1" rowspan="1">Value in base 45</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">%69 VD92EX0</td>
              <td align="left" colspan="1" rowspan="1">Encoded string</td>
            </tr>
          </tbody>
        </table>
        <t indent="0" pn="section-4.3-8">Encoding example 3:</t>
        <t indent="3" pn="section-4.3-9">
  The string "base-45" as ASCII is the byte sequence [[98 97] [115 101]
   [45 52] [53]].
  
  If we look at this two bytes at a time, we get [25185 29541 11572
   53].  Note the 53 for the last byte.
  
  When looking at the values in base 45, we get [[30 19 12] [21 26 14]
   [7 32 5] [8 1]] where the last byte is represented by two values.
  
  Referring to <xref target="table1" format="default" sectionFormat="of" derivedContent="Table 1"/>, we get the encoded string
   "UJCLQE7W581".
</t>
        <table align="center" pn="table-4">
          <name slugifiedName="name-example-3-in-detail">Example 3 in Detail</name>
          <tbody>
            <tr>
              <td align="left" colspan="1" rowspan="1">base-45</td>
              <td align="left" colspan="1" rowspan="1">Initial string</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[[98 97] [115 101] [45 52] [53]]</td>
              <td align="left" colspan="1" rowspan="1">Decimal value</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[25185 29541 11572 53]</td>
              <td align="left" colspan="1" rowspan="1">Value in base 16</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[[30 19 12] [21 26 14] [7 32 5] [8 1]]</td>
              <td align="left" colspan="1" rowspan="1">Value in base 45</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">UJCLQE7W581</td>
              <td align="left" colspan="1" rowspan="1">Encoded string</td>
            </tr>
          </tbody>
        </table>
      </section>
      <section numbered="true" toc="include" removeInRFC="false" pn="section-4.4">
        <name slugifiedName="name-decoding-example">Decoding Example</name>
        <t indent="0" pn="section-4.4-1">Decoding example 1:</t>
        <t indent="3" pn="section-4.4-2">
   The string "QED8WEX0" represents, when looked up in Table 1, the
   values [26 14 13 8 32 14 33 0].

     We arrange the numbers in chunks of three, except for the last one
   which can be two numbers, and get [[26 14 13] [8 32 14] [33 0]].
  
  In base 45, we get [26981 29798 33] where the bytes are [[105 101]
   [116 102] [33]].
  
     If we look at the ASCII values, we get the string "ietf!".
</t>
        <table align="center" pn="table-5">
          <name slugifiedName="name-example-4-in-detail">Example 4 in Detail</name>
          <tbody>
            <tr>
              <td align="left" colspan="1" rowspan="1">QED8WEX0</td>
              <td align="left" colspan="1" rowspan="1">Initial string</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[26 14 13 8 32 14 33 0]</td>
              <td align="left" colspan="1" rowspan="1">Looked up values</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[[26 14 13] [8 32 14] [33 0]]</td>
              <td align="left" colspan="1" rowspan="1">Groups of three</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[26981 29798 33]</td>
              <td align="left" colspan="1" rowspan="1">Interpreted as base 45</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">[[105 101] [116 102] [33]]</td>
              <td align="left" colspan="1" rowspan="1">Values in base 8</td>
            </tr>
            <tr>
              <td align="left" colspan="1" rowspan="1">ietf!</td>
              <td align="left" colspan="1" rowspan="1">Decoded string</td>
            </tr>
          </tbody>
        </table>
      </section>
    </section>
    <section numbered="true" toc="include" removeInRFC="false" pn="section-5">
      <name slugifiedName="name-iana-considerations">IANA Considerations</name>
      <t indent="0" pn="section-5-1">
	This document has no IANA actions.
      </t>
    </section>
    <section numbered="true" toc="include" removeInRFC="false" pn="section-6">
      <name slugifiedName="name-security-considerations">Security Considerations</name>
      <t indent="0" pn="section-6-1">
	When implementing encoding and decoding it is important to be
	very careful so that buffer overflow or similar issues do
	not occur.  This of course includes the calculations in base
	45 and lookup in the table of characters (<xref target="table1" format="default" sectionFormat="of" derivedContent="Table 1"/>). A decoder must also be robust regarding
	input, including proper handling of any octet value 0-255,
	including the NUL character (ASCII 0).
      </t>
      <t indent="0" pn="section-6-2">
	It should be noted that Base64 and some other encodings pad
	the string so that the encoding starts with an aligned number
	of characters while Base45 specifically avoids padding. Because of
	this, special care has to be taken when an odd number of octets
	is to be encoded. Similarly, care must be taken if the number
	of characters to decode are not evenly divisible by 3.
      </t>
      <t indent="0" pn="section-6-3">
	Base encodings use a specific, reduced alphabet to encode
	binary data. Non-alphabet characters could exist within
	base-encoded data, caused by data corruption or by
	design. Non-alphabet characters may be exploited as a "covert
	channel", where non-protocol data can be sent for nefarious
	purposes. Non-alphabet characters might also be sent in order
	to exploit implementation errors leading to, for example, buffer
	overflow attacks.
      </t>
      <t indent="0" pn="section-6-4">
	Implementations <bcp14>MUST</bcp14> reject any input that is
	not a valid encoding. For example, it <bcp14>MUST</bcp14>
	reject the input (encoded data) if it contains characters
	outside the base alphabet (in <xref target="table1" format="default" sectionFormat="of" derivedContent="Table 1"/>) when
	interpreting base-encoded data.
      </t>
      <t indent="0" pn="section-6-5">
	Even though a Base45-encoded string contains only characters
	from the alphabet in <xref target="table1" format="default" sectionFormat="of" derivedContent="Table 1"/>, cases like the
	following have to be considered: The string "FGW" represents
	65535 (FFFF in base 16), which is a valid encoding of 16 bits.
	A slightly different encoded string of the same length, "GGW",
	would represent 65536 (10000 in base 16), which is represented
	by more than 16 bits.  Implementations <bcp14>MUST</bcp14>
	also reject the encoded data if it contains a triplet of
	characters that, when decoded, results in an unsigned integer
	that is greater than 65535 (FFFF in base 16).
      </t>
      <t indent="0" pn="section-6-6">
	It should be noted that the resulting string after encoding to
	Base45 might include non-URL-safe characters so if the URL
	including the Base45 encoded data has to be URL-safe, one
	has to use percent-encoding.
      </t>
    </section>
  </middle>
  <back>
    <references pn="section-7">
      <name slugifiedName="name-normative-references">Normative References</name>
      <reference anchor="ISO18004" target="https://www.iso.org/standard/62021.html" quoteTitle="true" derivedAnchor="ISO18004">
        <front>
          <title>Information technology - Automatic identification and data capture techniques - QR Code bar code symbology specification</title>
          <author>
            <organization showOnFrontPage="true">ISO/IEC</organization>
          </author>
          <date month="February" year="2015"/>
        </front>
        <seriesInfo name="ISO/IEC" value="18004:2015"/>
      </reference>
      <reference anchor="RFC2119" target="https://www.rfc-editor.org/info/rfc2119" quoteTitle="true" derivedAnchor="RFC2119">
        <front>
          <title>Key words for use in RFCs to Indicate Requirement Levels</title>
          <author fullname="S. Bradner" initials="S" surname="Bradner"/>
          <date month="March" year="1997"/>
          <abstract>
            <t indent="0">In many standards track documents several words are used to signify the requirements in the specification.  These words are often capitalized.  This document defines these words as they should be interpreted in IETF documents.  This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</t>
          </abstract>
        </front>
        <seriesInfo name="BCP" value="14"/>
        <seriesInfo name="RFC" value="2119"/>
        <seriesInfo name="DOI" value="10.17487/RFC2119"/>
      </reference>
      <reference anchor="RFC4648" target="https://www.rfc-editor.org/info/rfc4648" quoteTitle="true" derivedAnchor="RFC4648">
        <front>
          <title>The Base16, Base32, and Base64 Data Encodings</title>
          <author fullname="S. Josefsson" initials="S" surname="Josefsson"/>
          <date month="October" year="2006"/>
          <abstract>
            <t indent="0">This document describes the commonly used base 64, base 32, and base 16 encoding schemes.  It also discusses the use of line-feeds in encoded data, use of padding in encoded data, use of non-alphabet characters in encoded data, use of different encoding alphabets, and canonical encodings. [STANDARDS-TRACK]</t>
          </abstract>
        </front>
        <seriesInfo name="RFC" value="4648"/>
        <seriesInfo name="DOI" value="10.17487/RFC4648"/>
      </reference>
      <reference anchor="RFC8174" target="https://www.rfc-editor.org/info/rfc8174" quoteTitle="true" derivedAnchor="RFC8174">
        <front>
          <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
          <author fullname="B. Leiba" initials="B" surname="Leiba"/>
          <date month="May" year="2017"/>
          <abstract>
            <t indent="0">RFC 2119 specifies common key words that may be used in protocol specifications.  This document aims to reduce the ambiguity by clarifying that only UPPERCASE usage of the key words have the defined special meanings.</t>
          </abstract>
        </front>
        <seriesInfo name="BCP" value="14"/>
        <seriesInfo name="RFC" value="8174"/>
        <seriesInfo name="DOI" value="10.17487/RFC8174"/>
      </reference>
    </references>
    <section numbered="false" toc="include" removeInRFC="false" pn="section-appendix.a">
      <name slugifiedName="name-acknowledgements">Acknowledgements</name>
      <t indent="0" pn="section-appendix.a-1">
	The authors thank <contact fullname="Mark Adler"/>, <contact fullname="Anders Ahl"/>, <contact fullname="Alan Barrett"/>, <contact fullname="Sam Spens Clason"/>, <contact fullname="Alfred Fiedler"/>, <contact fullname="Tomas Harreveld"/>, <contact fullname="Erik Hellman"/>, <contact fullname="Joakim Jardenberg"/>, <contact fullname="Michael Joost"/>, <contact fullname="Erik Kline"/>, <contact fullname="Christian Landgren"/>, <contact fullname="Anders Lowinger"/>, <contact fullname="Mans Nilsson"/>, <contact fullname="Jakob Schlyter"/>, <contact fullname="Peter Teufl"/>, and <contact fullname="Gaby Whitehead"/> for the feedback. Also, everyone who has been working with Base64 over a long period of years and has proven the implementations are stable.
      </t>
    </section>
    <section anchor="authors-addresses" numbered="false" removeInRFC="false" toc="include" pn="section-appendix.b">
      <name slugifiedName="name-authors-addresses">Authors' Addresses</name>
      <author fullname="Patrik Fältström" initials="P." surname="Fältström">
        <organization showOnFrontPage="true">Netnod</organization>
        <address>
          <email>paf@netnod.se</email>
        </address>
      </author>
      <author fullname="Fredrik Ljunggren" initials="F." surname="Ljunggren">
        <organization showOnFrontPage="true">Kirei</organization>
        <address>
          <email>fredrik@kirei.se</email>
        </address>
      </author>
      <author fullname="Dirk-Willem van Gulik" initials="D.W." surname="van Gulik">
        <organization showOnFrontPage="true">Webweaving</organization>
        <address>
          <email>dirkx@webweaving.org</email>
        </address>
      </author>
    </section>
  </back>
</rfc>
