<?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[Javascript &#x2F; Base64 encoding]]></title><description><![CDATA[<p dir="auto">Afternoon folks. I have a patch with a few TCP actors that need to send http headers, and part of the header is auth:basic.</p>
<div>I can grab the username and password via User Input actors / Text Input controls, and can concatenate it into username:password, but it then needs base64 encoding.</div>
<div>I'm using trigger text actor which is firing fred:west in as input1 to the javascript actor.</div>
<div>It's outputting -,+(0( for everything, so I'm assuming something is tripping it up - . How does one log to the javascript monitor?</div>
<div>The Javascript is running thus:</div>
<div>
<p dir="auto">function main()</p>
<p dir="auto">{</p>
<p dir="auto">//  discuss at: <a href="http://phpjs.org/functions/base64_encode/" rel="nofollow ugc">http://phpjs.org/functions/base64_encode/</a></p>
<p dir="auto">// original by: Tyler Akins (<a href="http://rumkin.com" rel="nofollow ugc">http://rumkin.com</a>)</p>
<p dir="auto">// improved by: Bayron Guevara</p>
<p dir="auto">// improved by: Thunder.m</p>
<p dir="auto">// improved by: Kevin van Zonneveld (<a href="http://kevin.vanzonneveld.net" rel="nofollow ugc">http://kevin.vanzonneveld.net</a>)</p>
<p dir="auto">// improved by: Kevin van Zonneveld (<a href="http://kevin.vanzonneveld.net" rel="nofollow ugc">http://kevin.vanzonneveld.net</a>)</p>
<p dir="auto">// improved by: Rafa∏ Kukawski (<a href="http://kukawski.pl" rel="nofollow ugc">http://kukawski.pl</a>)</p>
<p dir="auto">// bugfixed by: Pellentesque Malesuada</p>
<p dir="auto">//   example 1: base64_encode('Kevin van Zonneveld');</p>
<p dir="auto">//   returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='</p>
<p dir="auto">//   example 2: base64_encode('a');</p>
<p dir="auto">//   returns 2: 'YQ=='</p>
<p dir="auto">var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';</p>
<p dir="auto">var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,</p>
<p dir="auto">ac = 0,</p>
<p dir="auto">enc = '',</p>
<p dir="auto">tmp_arr = [];</p>
<p dir="auto">var data = arguments[0];</p>
<p dir="auto">if (!data) {</p>
<p dir="auto">return data;</p>
<p dir="auto">}</p>
<p dir="auto">do { // pack three octets into four hexets</p>
<p dir="auto">o1 = data.charCodeAt(i++);</p>
<p dir="auto">o2 = data.charCodeAt(i++);</p>
<p dir="auto">o3 = data.charCodeAt(i++);</p>
<p dir="auto">bits = o1 &lt;&lt; 16 | o2 &lt;&lt; 8 | o3;</p>
<p dir="auto">h1 = bits &gt;&gt; 18 &amp; 0x3f;</p>
<p dir="auto">h2 = bits &gt;&gt; 12 &amp; 0x3f;</p>
<p dir="auto">h3 = bits &gt;&gt; 6 &amp; 0x3f;</p>
<p dir="auto">h4 = bits &amp; 0x3f;</p>
<p dir="auto">// use hexets to index into b64, and append result to encoded string</p>
<p dir="auto">tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);</p>
<p dir="auto">} while (i &lt; data.length);</p>
<p dir="auto">enc = tmp_arr.join('');</p>
<p dir="auto">var r = data.length % 3;</p>
<p dir="auto">return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);</p>
<p dir="auto">}</p>
</div>]]></description><link>https://community.troikatronix.com/topic/2155/javascript-base64-encoding</link><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Mar 2026 09:59:08 GMT</lastBuildDate><atom:link href="https://community.troikatronix.com/topic/2155.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 29 Aug 2015 15:28:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Javascript &#x2F; Base64 encoding on Sun, 30 Aug 2015 14:25:07 GMT]]></title><description><![CDATA[<p dir="auto">glad you got it.</p>
]]></description><link>https://community.troikatronix.com/post/16954</link><guid isPermaLink="true">https://community.troikatronix.com/post/16954</guid><dc:creator><![CDATA[DusX]]></dc:creator><pubDate>Sun, 30 Aug 2015 14:25:07 GMT</pubDate></item><item><title><![CDATA[Reply to Javascript &#x2F; Base64 encoding on Sat, 29 Aug 2015 15:30:11 GMT]]></title><description><![CDATA[<p dir="auto">Nevermind... needed to plug the output to a text type actor to set the mutable type for the JS actor. Sorted!</p>
]]></description><link>https://community.troikatronix.com/post/16949</link><guid isPermaLink="true">https://community.troikatronix.com/post/16949</guid><dc:creator><![CDATA[Marci]]></dc:creator><pubDate>Sat, 29 Aug 2015 15:30:11 GMT</pubDate></item></channel></rss>