<?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[base64 problem...]]></title><description><![CDATA[<p>Hallihallo, ich hab ein kleines problem mit base64 codierung, und zwar wird nicht der korrekte schlüßel erzeugt. wenn mir da jemand einen kleinen tipp geben kann wäre ich sehr dankbar =))<br />
Nich wundern, das '=' ist als einziges noch nicht implementiert.</p>
<p>Hier der Source:</p>
<pre><code class="language-cpp">#pragma once
#include &lt;iostream&gt;
using namespace std;

char* base64_encode(const char *bytes, int size)
{
	const char* base64_charset = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/&quot;;

	int rest_bytes;
	int real_bytes;
	int base64_buffer;
	char *input_buffer;
	char *encoded_buffer;

	unsigned char in[3];
	unsigned char out[4];

	rest_bytes = size % 3;
	if(rest_bytes == 0)
		real_bytes = size;
	else if(rest_bytes == 1)
		real_bytes = size + 2;
	else if(rest_bytes == 2)
		real_bytes = size + 1;

	input_buffer = new char[real_bytes];
	memset(input_buffer, 0, real_bytes);
	//strcpy(input_buffer, bytes);
	memcpy(input_buffer, bytes, size);

	base64_buffer = 4 * real_bytes / 3;
	encoded_buffer = new char[base64_buffer + 1];
	memset(encoded_buffer, 0, base64_buffer + 1);

	for(int i = 0, k = 0; i &lt; real_bytes; i += 3, k += 4)
	{
		in[0] = input_buffer[i + 0];
		in[1] = input_buffer[i + 1];
		in[2] = input_buffer[i + 2];

		out[0] = (in[0] &amp; 0xFC) &gt;&gt; 2;
		out[1] = ((in[0] &amp; 0x03) &lt;&lt; 4) | ((in[1] &amp; 0xF0) &gt;&gt; 4);
		out[2] = ((in[1] &amp; 0x0F) &lt;&lt; 2) | ((in[2] &amp; 0xC0) &gt;&gt; 6);
		out[3] = (in[2] &amp; 0x3F);

		for(int j = 0; j &lt; 4; j++)
		{
			encoded_buffer[j + k] = base64_charset[out[j&rsqb;&rsqb;;
		}
	}
	encoded_buffer[base64_buffer] = '\0';

	if(input_buffer != NULL)
		delete[] input_buffer;

	return encoded_buffer;
}
</code></pre>
<p>Vielen Dank im voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/151734/base64-problem</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 15:51:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/151734.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Jun 2006 06:31:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to base64 problem... on Thu, 29 Jun 2006 06:31:58 GMT]]></title><description><![CDATA[<p>Hallihallo, ich hab ein kleines problem mit base64 codierung, und zwar wird nicht der korrekte schlüßel erzeugt. wenn mir da jemand einen kleinen tipp geben kann wäre ich sehr dankbar =))<br />
Nich wundern, das '=' ist als einziges noch nicht implementiert.</p>
<p>Hier der Source:</p>
<pre><code class="language-cpp">#pragma once
#include &lt;iostream&gt;
using namespace std;

char* base64_encode(const char *bytes, int size)
{
	const char* base64_charset = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/&quot;;

	int rest_bytes;
	int real_bytes;
	int base64_buffer;
	char *input_buffer;
	char *encoded_buffer;

	unsigned char in[3];
	unsigned char out[4];

	rest_bytes = size % 3;
	if(rest_bytes == 0)
		real_bytes = size;
	else if(rest_bytes == 1)
		real_bytes = size + 2;
	else if(rest_bytes == 2)
		real_bytes = size + 1;

	input_buffer = new char[real_bytes];
	memset(input_buffer, 0, real_bytes);
	//strcpy(input_buffer, bytes);
	memcpy(input_buffer, bytes, size);

	base64_buffer = 4 * real_bytes / 3;
	encoded_buffer = new char[base64_buffer + 1];
	memset(encoded_buffer, 0, base64_buffer + 1);

	for(int i = 0, k = 0; i &lt; real_bytes; i += 3, k += 4)
	{
		in[0] = input_buffer[i + 0];
		in[1] = input_buffer[i + 1];
		in[2] = input_buffer[i + 2];

		out[0] = (in[0] &amp; 0xFC) &gt;&gt; 2;
		out[1] = ((in[0] &amp; 0x03) &lt;&lt; 4) | ((in[1] &amp; 0xF0) &gt;&gt; 4);
		out[2] = ((in[1] &amp; 0x0F) &lt;&lt; 2) | ((in[2] &amp; 0xC0) &gt;&gt; 6);
		out[3] = (in[2] &amp; 0x3F);

		for(int j = 0; j &lt; 4; j++)
		{
			encoded_buffer[j + k] = base64_charset[out[j&rsqb;&rsqb;;
		}
	}
	encoded_buffer[base64_buffer] = '\0';

	if(input_buffer != NULL)
		delete[] input_buffer;

	return encoded_buffer;
}
</code></pre>
<p>Vielen Dank im voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088068</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088068</guid><dc:creator><![CDATA[VirtualDreams]]></dc:creator><pubDate>Thu, 29 Jun 2006 06:31:58 GMT</pubDate></item><item><title><![CDATA[Reply to base64 problem... on Thu, 29 Jun 2006 06:46:36 GMT]]></title><description><![CDATA[<p>Lass dir Zwischenergebnisse ausgeben, rechne von Hand nach und grenze so das Problem ein. Ich weiß noch nicht mal, was denn als Ergebnis rauskommen soll geschweige denn was für ein Algorithmus das ist, also kann ich dir schlecht helfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088071</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088071</guid><dc:creator><![CDATA[Michael E. logged out]]></dc:creator><pubDate>Thu, 29 Jun 2006 06:46:36 GMT</pubDate></item><item><title><![CDATA[Reply to base64 problem... on Thu, 29 Jun 2006 13:51:41 GMT]]></title><description><![CDATA[<p>Du kannst dir auch die Klasse hier runterladen <a href="http://www.codeguru.com/cpp/cpp/algorithms/article.php/c5099/" rel="nofollow">http://www.codeguru.com/cpp/cpp/algorithms/article.php/c5099/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088407</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088407</guid><dc:creator><![CDATA[Chris++ 0]]></dc:creator><pubDate>Thu, 29 Jun 2006 13:51:41 GMT</pubDate></item><item><title><![CDATA[Reply to base64 problem... on Thu, 29 Jun 2006 16:14:13 GMT]]></title><description><![CDATA[<p>Ich weiß ich weiß, es gibt einiges zum herunterladen. Aber ich bin nun mal der Typ der es lieber selbst auf die Reihe bekommen möchte ^^. Warum immer nur c&amp;p?<br />
Ist doch langweilig, da brauch ich ja nix mehr lernen geschweige denn programmieren =))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088523</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088523</guid><dc:creator><![CDATA[VirtualDreams]]></dc:creator><pubDate>Thu, 29 Jun 2006 16:14:13 GMT</pubDate></item><item><title><![CDATA[Reply to base64 problem... on Thu, 29 Jun 2006 16:35:38 GMT]]></title><description><![CDATA[<blockquote>
<p>und zwar wird nicht der korrekte schlüßel erzeugt.</p>
</blockquote>
<p>gib doch mal ein beispiel für den input, den entstehenden output und das erwartete ergebnis. auf den ersten blick fällt mir an der funktion nichts auf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088538</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088538</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 29 Jun 2006 16:35:38 GMT</pubDate></item><item><title><![CDATA[Reply to base64 problem... on Thu, 29 Jun 2006 16:48:10 GMT]]></title><description><![CDATA[<p>Also, der Inputstring ist &quot;Hello World!&quot; und der Output ohne &quot;=&quot; falls böntigt ist &quot;SGVsbG8gV29ybGQh&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088550</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088550</guid><dc:creator><![CDATA[VirtualDreams]]></dc:creator><pubDate>Thu, 29 Jun 2006 16:48:10 GMT</pubDate></item><item><title><![CDATA[Reply to base64 problem... on Thu, 29 Jun 2006 17:14:35 GMT]]></title><description><![CDATA[<p>VirtualDreams schrieb:</p>
<blockquote>
<p>Also, der Inputstring ist &quot;Hello World!&quot; und der Output ohne &quot;=&quot; falls böntigt ist &quot;SGVsbG8gV29ybGQh&quot;</p>
</blockquote>
<p>das ist doch auch richtig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088574</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088574</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 29 Jun 2006 17:14:35 GMT</pubDate></item><item><title><![CDATA[Reply to base64 problem... on Thu, 29 Jun 2006 17:42:06 GMT]]></title><description><![CDATA[<p>Ist jetzt nicht wahr, oder? Hatte einen string von der wikipdia probiert und da stimmt das mit meinem nicht überein ??? Aber das freut mich wirklich wenn das stimmt. Danke nochmal!!!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1088591</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1088591</guid><dc:creator><![CDATA[VirtualDreams]]></dc:creator><pubDate>Thu, 29 Jun 2006 17:42:06 GMT</pubDate></item><item><title><![CDATA[Reply to base64 problem... on Wed, 09 Aug 2006 06:40:27 GMT]]></title><description><![CDATA[<p>wieso hast du kein padding drin (=)? was passiert mit den letzten beiden byte bei dir, d.h. wenn weniger als 24bit am ende übrig bleiben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1113444</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1113444</guid><dc:creator><![CDATA[Sunday]]></dc:creator><pubDate>Wed, 09 Aug 2006 06:40:27 GMT</pubDate></item></channel></rss>