<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Turbo C++ Base64]]></title><description><![CDATA[<p>Hallo, also eigtl wollte ich eine Array die \0 terminiert ist base64 codieren.<br />
das ganze muss über DOS lauffähig sein und mit turbo c++ übersetzt werden.<br />
glaube das das Null terminieren nicht so ganz sauber läuft ..<br />
leider habe ich keine Idee wie ich das besser realisieren kann.<br />
evtl weiß jemand Rat ,<br />
Gruß Tom</p>
<p>Ausgabe:</p>
<pre><code>base64: QUJDREVGR0FCQ0RFRkFCQ0RFRgZ♂È ►&gt;Ì☺
text: ABCDEFGABCDEFABCDEF♠@L
</code></pre>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;iostream.h&gt;

static unsigned char b64e[] = {
  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', /*  0- 7 */
  'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', /*  8-15 */
  'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', /* 16-23 */
  'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', /* 24-31 */
  'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 32-39 */
  'o', 'p', 'q', 'r', 's', 't', 'u', 'v', /* 40-47 */
  'w', 'x', 'y', 'z', '0', '1', '2', '3', /* 48-55 */
  '4', '5', '6', '7', '8', '9', '+', '/'  /* 56-63 */
};

static unsigned char b64d[] = {
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0x00-0x0F */
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0x10-0x1F */
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x3f, /* 0x20-0x2F */
  0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x00,0x00,0x00,0x00,0x00,0x00, /* 0x30-0x3F */
  0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e, /* 0x40-0x4F */
  0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x00,0x00,0x00,0x00,0x00, /* 0x50-0x5F */
  0x00,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28, /* 0x60-0x6F */
  0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x00,0x00,0x00,0x00,0x00  /* 0x70-0x7F */
};

void b64encode(unsigned char *in, unsigned char *out)
{
  int inlen = strlen(in);
  while (inlen &gt; 0) {
    unsigned char t0 = (inlen &gt; 0) ? in[0] : 0;
    unsigned char t1 = (inlen &gt; 1) ? in[1] : 0;
    unsigned char t2 = (inlen &gt; 2) ? in[2] : 0;

    if (inlen &lt;= 0) return;
    out[0] = b64e[(t0 &gt;&gt; 2) &amp; 0x3f];
    out[1] = b64e[((t0 &lt;&lt; 4) &amp; 0x30) | (t1 &gt;&gt; 4)];

    if (inlen &lt;= 1) return;
    out[2] = b64e[((t1 &lt;&lt; 2) &amp; 0x3c) | (t2 &gt;&gt; 6)];

    if (inlen &lt;= 2) return;
    out[3] = b64e[t2 &amp; 0x3f];
    inlen -= 3;
    in += 3;
    out += 4;
  }
}

void b64decode(unsigned char *in, unsigned char *out) {
  int inlen = strlen(in);
  while (inlen &gt; 0) {
    unsigned char t0 = (inlen &gt; 0) ? b64d[in[0] &amp; 0x7f] : 0;
    unsigned char t1 = (inlen &gt; 1) ? b64d[in[1] &amp; 0x7f] : 0;
    unsigned char t2 = (inlen &gt; 2) ? b64d[in[2] &amp; 0x7f] : 0;
    unsigned char t3 = (inlen &gt; 3) ? b64d[in[3] &amp; 0x7f] : 0;

    if (inlen &lt;= 0) return;
      out[0] = (t0 &lt;&lt; 2) | (t1 &gt;&gt; 4);
    if (inlen &lt;= 1) {
      out[1] = 0;
      return;
    }
    out[1] = (t1 &lt;&lt; 4) | ((t2 &amp; 0x3c) &gt;&gt; 2);
    if (inlen &lt;= 2) {
      out[2] = 0;
      return;
    }
    out[2] = (t2 &lt;&lt; 6) | t3;

    inlen -= 4;
    in += 4;
    out += 3;
  }
}

int main(void)
{
char in[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'A', 'B', 'C', 'D', 'E', 'F','A', 'B', 'C', 'D', 'E', 'F', '\0'};
char out[100];
char text[100];

b64encode(in, out);

cout &lt;&lt; &quot;base64: &quot; &lt;&lt; out &lt;&lt; endl;

b64decode(out, text);

cout &lt;&lt; &quot;text: &quot; &lt;&lt; text &lt;&lt; endl;
return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/194157/turbo-c-base64</link><generator>RSS for Node</generator><lastBuildDate>Mon, 28 Sep 2026 08:22:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/194157.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 03 Oct 2007 16:12:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Turbo C++ Base64 on Wed, 03 Oct 2007 16:12:00 GMT]]></title><description><![CDATA[<p>Hallo, also eigtl wollte ich eine Array die \0 terminiert ist base64 codieren.<br />
das ganze muss über DOS lauffähig sein und mit turbo c++ übersetzt werden.<br />
glaube das das Null terminieren nicht so ganz sauber läuft ..<br />
leider habe ich keine Idee wie ich das besser realisieren kann.<br />
evtl weiß jemand Rat ,<br />
Gruß Tom</p>
<p>Ausgabe:</p>
<pre><code>base64: QUJDREVGR0FCQ0RFRkFCQ0RFRgZ♂È ►&gt;Ì☺
text: ABCDEFGABCDEFABCDEF♠@L
</code></pre>
<pre><code class="language-cpp">#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;iostream.h&gt;

static unsigned char b64e[] = {
  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', /*  0- 7 */
  'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', /*  8-15 */
  'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', /* 16-23 */
  'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', /* 24-31 */
  'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 32-39 */
  'o', 'p', 'q', 'r', 's', 't', 'u', 'v', /* 40-47 */
  'w', 'x', 'y', 'z', '0', '1', '2', '3', /* 48-55 */
  '4', '5', '6', '7', '8', '9', '+', '/'  /* 56-63 */
};

static unsigned char b64d[] = {
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0x00-0x0F */
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0x10-0x1F */
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x3f, /* 0x20-0x2F */
  0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x00,0x00,0x00,0x00,0x00,0x00, /* 0x30-0x3F */
  0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e, /* 0x40-0x4F */
  0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x00,0x00,0x00,0x00,0x00, /* 0x50-0x5F */
  0x00,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28, /* 0x60-0x6F */
  0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x00,0x00,0x00,0x00,0x00  /* 0x70-0x7F */
};

void b64encode(unsigned char *in, unsigned char *out)
{
  int inlen = strlen(in);
  while (inlen &gt; 0) {
    unsigned char t0 = (inlen &gt; 0) ? in[0] : 0;
    unsigned char t1 = (inlen &gt; 1) ? in[1] : 0;
    unsigned char t2 = (inlen &gt; 2) ? in[2] : 0;

    if (inlen &lt;= 0) return;
    out[0] = b64e[(t0 &gt;&gt; 2) &amp; 0x3f];
    out[1] = b64e[((t0 &lt;&lt; 4) &amp; 0x30) | (t1 &gt;&gt; 4)];

    if (inlen &lt;= 1) return;
    out[2] = b64e[((t1 &lt;&lt; 2) &amp; 0x3c) | (t2 &gt;&gt; 6)];

    if (inlen &lt;= 2) return;
    out[3] = b64e[t2 &amp; 0x3f];
    inlen -= 3;
    in += 3;
    out += 4;
  }
}

void b64decode(unsigned char *in, unsigned char *out) {
  int inlen = strlen(in);
  while (inlen &gt; 0) {
    unsigned char t0 = (inlen &gt; 0) ? b64d[in[0] &amp; 0x7f] : 0;
    unsigned char t1 = (inlen &gt; 1) ? b64d[in[1] &amp; 0x7f] : 0;
    unsigned char t2 = (inlen &gt; 2) ? b64d[in[2] &amp; 0x7f] : 0;
    unsigned char t3 = (inlen &gt; 3) ? b64d[in[3] &amp; 0x7f] : 0;

    if (inlen &lt;= 0) return;
      out[0] = (t0 &lt;&lt; 2) | (t1 &gt;&gt; 4);
    if (inlen &lt;= 1) {
      out[1] = 0;
      return;
    }
    out[1] = (t1 &lt;&lt; 4) | ((t2 &amp; 0x3c) &gt;&gt; 2);
    if (inlen &lt;= 2) {
      out[2] = 0;
      return;
    }
    out[2] = (t2 &lt;&lt; 6) | t3;

    inlen -= 4;
    in += 4;
    out += 3;
  }
}

int main(void)
{
char in[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'A', 'B', 'C', 'D', 'E', 'F','A', 'B', 'C', 'D', 'E', 'F', '\0'};
char out[100];
char text[100];

b64encode(in, out);

cout &lt;&lt; &quot;base64: &quot; &lt;&lt; out &lt;&lt; endl;

b64decode(out, text);

cout &lt;&lt; &quot;text: &quot; &lt;&lt; text &lt;&lt; endl;
return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1377317</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1377317</guid><dc:creator><![CDATA[kronos33]]></dc:creator><pubDate>Wed, 03 Oct 2007 16:12:00 GMT</pubDate></item><item><title><![CDATA[Reply to Turbo C++ Base64 on Wed, 03 Oct 2007 16:53:50 GMT]]></title><description><![CDATA[<p>Was stimmt denn daran nicht (ich hab keine Ahnung von der Thematik base64)?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1377347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1377347</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Wed, 03 Oct 2007 16:53:50 GMT</pubDate></item><item><title><![CDATA[Reply to Turbo C++ Base64 on Wed, 03 Oct 2007 17:37:27 GMT]]></title><description><![CDATA[<p>ich habe keine ahnung wie ich den string am ende Null terminiere ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1377379</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1377379</guid><dc:creator><![CDATA[kronos33]]></dc:creator><pubDate>Wed, 03 Oct 2007 17:37:27 GMT</pubDate></item><item><title><![CDATA[Reply to Turbo C++ Base64 on Wed, 03 Oct 2007 17:50:35 GMT]]></title><description><![CDATA[<p>Sag das doch gleich <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /> Du musst dazu nur die Länge des Strings wissen. str[laenge] setzt du dann auf '\0', das wars <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
(Der Speicher muss dafür natürlich ausreichen)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1377387</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1377387</guid><dc:creator><![CDATA[Badestrand]]></dc:creator><pubDate>Wed, 03 Oct 2007 17:50:35 GMT</pubDate></item></channel></rss>