Base64 encode data: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 5:
 
=={{header|ABAP}}==
<langsyntaxhighlight lang=ABAP>DATA: li_client TYPE REF TO if_http_client,
lv_encoded TYPE string,
lv_data TYPE xstring.
Line 32:
ENDWHILE.
WRITE: / lv_encoded.
</syntaxhighlight>
</lang>
 
{{out}}
Line 43:
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<langsyntaxhighlight lang=Action!>INCLUDE "D2:IO.ACT" ;from the Action! Tool Kit
 
PROC Encode(BYTE ARRAY buf BYTE len CHAR ARRAY res)
Line 95:
PROC Main()
EncodeFile("H1:FAVICON.ICO")
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Base64_encode_data.png Screenshot from Atari 8-bit computer]
Line 106:
=={{header|Ada}}==
{{libheader|AWS}}
<langsyntaxhighlight lang=Ada>with Ada.Text_IO;
 
with AWS.Response;
Line 119:
begin
Ada.Text_IO.Put_Line (Icon_64);
end Encode_AWS;</langsyntaxhighlight>
 
{{out}}
Line 130:
=={{header|ALGOL 68}}==
This program is run on a modified Algol 68 Genie 2.8. That interpreter has some bugs, so it does not do binary tcp/ip requests, and I made patches/bugfixes to it in order to run this task.
<langsyntaxhighlight lang=algol68>
STRING codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[@0];
 
Line 194:
STRING encoded icon = base64_encode (rosettacode icon);
print ((encoded icon, new line))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 204:
 
=={{header|ARM Assembly}}==
<langsyntaxhighlight lang=ARM Assembly>
.section .rodata
ch64: .ascii "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Line 371:
mov r0, #0
swi #0
</syntaxhighlight>
</lang>
 
=={{header|BaCon}}==
<langsyntaxhighlight lang=bacon>CONST file$ = "favicon.ico"
binary = BLOAD(file$)
PRINT B64ENC$(binary, FILELEN(file$))
FREE binary</langsyntaxhighlight>
{{out}}
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAE.......QAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAE=</pre>
Line 384:
===libresolv===
{{libheader|libresolv}} (libresolv is included on most Unix-like systems)
<langsyntaxhighlight lang=c>#include <stdio.h>
#include <stdlib.h>
#include <resolv.h>
Line 422:
 
return 0;
}</langsyntaxhighlight>
Compile with
<pre>gcc -lresolv -o base64encode base64encode.c</pre>
Line 428:
===Manual implementation===
The following reads standard input and writes base64-encoded stream to standard output, e.g. <tt>./a.out <some_random_file >/dev/null</tt> if you don't want to see the output. It gives identical output as the common <tt>base64</tt> utility program, though much less efficiently.
<langsyntaxhighlight lang=c>#include <stdio.h>
#include <unistd.h>
 
Line 458:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang=csharp>namespace RosettaCode.Base64EncodeData
{
using System;
Line 482:
}
}
}</langsyntaxhighlight>
Output:
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAg...AAABAAAAAQAAAAEAAAABAAAAAQAAAAE=</pre>
 
=={{header|C++}}==
<langsyntaxhighlight lang=cpp>
#include <iostream>
#include <fstream>
Line 544:
return 0;
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 557:
Assumes the source file is a PRG on disk drive device 8, writes encoded file both to a SEQ file on the same disk and to the screen (where it looks good in 80-column mode on a PET or C128, a little less so on a C64 or VIC). This is all done in PETSCII; transfer out of Commodore-land will require translation of the Base64-encoded file into ASCII.
 
<langsyntaxhighlight lang=basic>
100 print chr$(247);chr$(14);
110 dim a$(63): rem alphabet
Line 595:
450 print "error:"st
460 open 15,8,15:input#15,ds,ds$,a,b:close15
470 print ds,ds$,a,b</langsyntaxhighlight>
 
{{Out}}
Line 609:
A nice example for the CL eco system using [http://quickdocs.org/cl-base64/ cl-base64] and [https://www.cliki.net/Drakma drakma].
<langsyntaxhighlight lang=lisp>(eval-when (:load-toplevel :compile-toplevel :execute)
(ql:quickload "drakma")
(ql:quickload "cl-base64"))
Line 630:
finally (return (usb8-array-to-base64-string array)))))
(close input)
output))</langsyntaxhighlight>
{{out}}
<pre>"AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///...</pre>
 
=={{header|Crystal}}==
<langsyntaxhighlight lang=ruby>
require "http/client"
require "base64"
Line 643:
Base64.encode(response.body, STDOUT)
end
</syntaxhighlight>
</lang>
 
 
=={{header|D}}==
<langsyntaxhighlight lang=d>void main() {
import std.stdio, std.base64, std.net.curl, std.string;
 
const f = "http://rosettacode.org/favicon.ico".get.representation;
Base64.encode(f).writeln;
}</langsyntaxhighlight>
{{out}}
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAwqgIAADCjgUAACgAAAAQAAAAIAA...
Line 658:
 
=={{header|Delphi}}==
<langsyntaxhighlight lang=delphi>program Base64EncodeData;
{$APPTYPE CONSOLE}
uses IdHTTP, IdCoderMIME;
Line 673:
lHTTP.Free;
end;
end.</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang=elixir>data = File.read!("favicon.ico")
encoded = :base64.encode(data)
IO.puts encoded</langsyntaxhighlight>
 
{{out}}
Line 688:
 
=={{header|Erlang}}==
<langsyntaxhighlight lang=erlang>-module(base64demo).
-export([main/0]).
 
Line 698:
%% Demonstrating with the library function.
encode_library(Data) ->
base64:encode(Data).</langsyntaxhighlight>
 
{{out}}
Line 706:
===Standard Library===
{{works with|fsharp|4.5}}
<langsyntaxhighlight lang=fsharp>open System
open System.Net
 
Line 718:
let encoded = Convert.ToBase64String raw
 
printfn "%s" encoded</langsyntaxhighlight>
 
{{out}}
Line 725:
===Manual Implementation===
{{works with|fsharp|4.5}}
<langsyntaxhighlight lang=fsharp>open System.Net
 
let encode s =
Line 755:
 
printfn "%s" encoded
</syntaxhighlight>
</lang>
 
{{out}}
Line 761:
 
=={{header|Factor}}==
<langsyntaxhighlight lang=factor>USING: base64 http.client io kernel strings ;
 
"http://rosettacode.org/favicon.ico" http-get nip
>base64-lines >string print</langsyntaxhighlight>
{{out}}
<pre>
Line 776:
Inspired from Wikipedia. Use of a buffer.
May be also of interest : github.com/lietho/base64-forth
<langsyntaxhighlight lang=forth>variable bitsbuff
 
: alphabase ( u -- c ) $3F and C" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 1+ + c@ ;
Line 805:
dup here swap - ( addr2 n2 )
;
</syntaxhighlight>
</lang>
 
{{out}}
Line 820:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang=freebasic>Dim Shared As String B64
B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" & _
"abcdefghijklmnopqrstuvwxyz" & _
Line 860:
Print msg64
Print: Print(Encode64(msg64))
Sleep</langsyntaxhighlight>
{{out}}
<pre>To err is human, but to really foul things up you need a computer.
Line 870:
=={{header|Go}}==
===Standard Library===
<langsyntaxhighlight lang=Go>package main
 
import (
Line 892:
}
fmt.Println(base64.StdEncoding.EncodeToString(d))
}</langsyntaxhighlight>
{{out}}
<pre>
Line 898:
</pre>
===Manual implementation===
<langsyntaxhighlight lang=go>// base64 encoding
// A port, with slight variations, of the C version found here:
// http://rosettacode.org/wiki/Base64#C (manual implementation)
Line 998:
}
fmt.Printf("%s", encoded)
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,012:
{{Trans|C}}
This Haskell code is ported from the C solution (manual implementation) with slight variations.
<langsyntaxhighlight lang=Haskell>-- | Base 64 Encoding.
-- A port, with slight variations, of the C version found here:
-- http://rosettacode.org/wiki/Base64#C (manual implementation)
Line 1,077:
 
main :: IO ()
main = C.getContents >>= C.putStr . b64EncodePretty</langsyntaxhighlight>
 
===Using Data.ByteString.Base64===
<langsyntaxhighlight lang=haskell>import qualified Data.ByteString.Base64 as Base64 (decode, encode)
import qualified Data.ByteString.Char8 as B (putStrLn, readFile)
 
main :: IO ()
main = B.readFile "favicon.ico" >>= (B.putStrLn . Base64.encode)</langsyntaxhighlight>
 
=={{header|J}}==
'''Solution''' (''[http://www.jsoftware.com/wsvn/addons/trunk/convert/misc/base64.ijs standard library]''):<langsyntaxhighlight lang=j> load'convert/misc/base64' NB. use 'tobase64'</langsyntaxhighlight>
'''Solution''' (''handrolled''):<langsyntaxhighlight lang=j> tobase64 =: padB64~ b2B64
padB64 =: , '=' #~ 0 2 1 i. 3 | #
b2B64 =: BASE64 {~ _6 #.\ (8#2) ,@:#: a.&i.</langsyntaxhighlight>
'''Example''':<langsyntaxhighlight lang=j> load'web/gethttp'
76 {. tobase64 gethttp 'http://rosettacode.org/favicon.ico'
AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAA</langsyntaxhighlight>
 
=={{header|Java}}==
Line 1,099:
Can also use org.apache.commons.codec.binary.Base64 from Apache Commons Codec
 
<langsyntaxhighlight lang=Java>import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Line 1,169:
}
}
}</langsyntaxhighlight>
<pre>AAABAAIAEBAAAAAAAABoBQ...QAAAAEAAAABAAAAAQAAAAE=</pre>
 
=== Java 8 version ===
<langsyntaxhighlight lang=java>import java.nio.file.*;
import java.util.Base64;
 
Line 1,183:
System.out.println(result);
}
}</langsyntaxhighlight>
 
<pre>AAABAAIAEBAAAAAAAABoBQ...QAAAAEAAAABAAAAAQAAAAE=</pre>
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang=JavaScript>(function(){//ECMAScript doesn't have an internal base64 function or method, so we have to do it ourselves, isn't that exciting?
function stringToArrayUnicode(str){for(var i=0,l=str.length,n=[];i<l;i++)n.push(str.charCodeAt(i));return n;}
function generateOnesByLength(n){//Attempts to generate a binary number full of ones given a length.. they don't redefine each other that much.
Line 1,252:
 
return toBase64(stringToArrayUnicode("Nothing seems hard to the people who don't know what they're talking about."))
}())</langsyntaxhighlight>
 
===Using btoa (HTML5)===
Line 1,260:
HTML5 saves the day! introducing two methods to the DOM!
These are btoa and atob, see [http://dev.w3.org/html5/spec-LC/webappapis.html#atob spec]
<langsyntaxhighlight lang=JavaScript>window.btoa("String to encode, etc..");//Will throw error if any unicode character is larger than 255 it's counterpart it's the window.atob</langsyntaxhighlight>To make it.. just work, you could convert it to UTF-8 Manually or..
JSON.stringify it or..
encodeURIComponent it.
Line 1,266:
===Using Node.js===
{{works with|Node.js}}
<langsyntaxhighlight lang=JavaScript>var http = require('http');
var options = {
host: 'rosettacode.org',
Line 1,280:
});
}
</syntaxhighlight>
</lang>
 
=={{header|Jsish}}==
Line 1,286:
<nowiki>https://jsish.org/fossil/jsi/wiki/Wget</nowiki> and also listed at [[HTTP#Jsish]].
 
<langsyntaxhighlight lang=javascript>/* Base64, in Jsish */
require('httpGet');
var icon = httpGet('http://rosettacode.org/favicon.ico');
printf("%s", Util.base64(icon, false))</langsyntaxhighlight>
 
{{out}}
Line 1,311:
{{works with|Julia|0.6}}
 
<langsyntaxhighlight lang=julia>using Requests
 
file = read(get("https://rosettacode.org/favicon.ico"))
encoded = base64encode(file)
 
print(encoded)</langsyntaxhighlight>
 
{{out}}
Line 1,322:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang=scala>// version 1.1.2
 
import java.io.File
Line 1,332:
val base64 = Base64.getEncoder().encodeToString(bytes)
println(base64)
}</langsyntaxhighlight>
 
{{out}}
Line 1,340:
 
=={{header|Lasso}}==
<langsyntaxhighlight lang=Lasso >local(
src = curl('http://rosettacode.org/favicon.ico'),
srcdata = #src->result
Line 1,347:
 
// or, in one movement:
curl('http://rosettacode.org/favicon.ico')->result->encodebase64</langsyntaxhighlight>
 
=={{header|LiveCode}}==
<langsyntaxhighlight lang=LiveCode>put URL "http://rosettacode.org/favicon.ico" into rosettaico
put base64encode(rosettaico)
 
Ouput
AAABAA...S0tLS0tLS0t...QAAAAE=</langsyntaxhighlight>
 
=={{header|Lua}}==
<langsyntaxhighlight lang=lua>
local dic = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
function encode( t, f )
Line 1,389:
end
print()
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,400:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight lang=Mathematica>ExportString[Import["http://rosettacode.org/favicon.ico", "Text"], "Base64"]</langsyntaxhighlight>
Very interesting results.
{{out}}
Line 1,412:
 
=={{header|Nim}}==
<langsyntaxhighlight lang=Nim>import base64
import httpclient
 
Line 1,422:
echo encoded
else:
echo encoded[0..31] & "..." & encoded[^32..^1]</langsyntaxhighlight>
 
{{out}}
Line 1,430:
{{works with|Mac OS X|10.6+}}
{{works with|iOS|4.0+}}
<langsyntaxhighlight lang=objc>#import <Foundation/Foundation.h>
 
int main(int argc, const char *argv[]) {
Line 1,438:
}
return 0;
}</langsyntaxhighlight>
 
=={{header|OCaml}}==
Line 1,469:
 
=={{header|Ol}}==
<langsyntaxhighlight lang=scheme>
(define base64-codes "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
(define kernel (alist->ff (map cons (iota (string-length base64-codes)) (string->bytes base64-codes))))
Line 1,518:
 
(encode "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.")
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 1,527:
 
The rosettacode icon:
<langsyntaxhighlight lang=scheme>
(define icon (runes->string (bytevector->list (file->bytevector "favicon.ico"))))
(encode icon)
</syntaxhighlight>
</lang>
<pre>
AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wCG
Line 1,538:
 
=={{header|Perl}}==
<langsyntaxhighlight lang=perl>#!perl
use strict;
use warnings;
Line 1,545:
local $/;
print encode_base64(<$fh>);
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,554:
=={{header|Phix}}==
For simplicity, the example from wp:
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #000000;">base64</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 1,565:
<span style="color: #0000FF;">?</span><span style="color: #000000;">e</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">decode_base64</span><span style="color: #0000FF;">(</span><span style="color: #000000;">e</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,576:
This downloads, encodes, decodes, and verifies the icon:
{{libheader|Phix/libcurl}}
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">url</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"https://rosettacode.org/favicon.ico"</span><span style="color: #0000FF;">,</span>
Line 1,596:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"base 64: %s, same: %t\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">b64</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"chars"</span><span style="color: #0000FF;">),</span><span style="color: #000000;">chk</span><span style="color: #0000FF;">==</span><span style="color: #000000;">raw</span><span style="color: #0000FF;">})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,606:
 
=={{header|PHP}}==
<langsyntaxhighlight lang=php><?php echo base64_encode(file_get_contents("http://rosettacode.org/favicon.ico"));/*1 liner*/ ?></langsyntaxhighlight>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight lang=PicoLisp>`(== 64 64)
(setq *Char64
`'(chop
Line 1,653:
(test
"c3VyZS4="
(base64 "sure.") )</langsyntaxhighlight>
 
=={{header|Pike}}==
<langsyntaxhighlight lang=Pike>
string icon = Protocols.HTTP.get_url_data("http://rosettacode.org/favicon.ico");
// The default base64 encodeing linefeeds every 76 chars
Line 1,662:
// For brivety, just print the first and last line
write("%s\n...\n%s\n", encoded_lines[0], encoded_lines[-1]);
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 1,671:
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang=PowerShell>$webClient = [Net.WebClient]::new()
$bytes = $webClient.DownloadData('http://rosettacode.org/favicon.ico')
$output = [Convert]::ToBase64String($bytes)
$output</langsyntaxhighlight>
{{out}}
<pre>
Line 1,683:
 
=={{header|PureBasic}}==
<langsyntaxhighlight lang=purebasic>InitNetwork()
*BufferRaw = ReceiveHTTPMemory("http://rosettacode.org/favicon.ico")
Line 1,690:
Else
Debug "Download failed"
EndIf</langsyntaxhighlight>
 
=={{header|Python}}==
<langsyntaxhighlight lang=python>import urllib
import base64
 
data = urllib.urlopen('http://rosettacode.org/favicon.ico').read()
print base64.b64encode(data)</langsyntaxhighlight>
(For me this gets the wrong data; the data is actually an error message. But still, it base-64 encodes it.)
 
=={{header|Racket}}==
<langsyntaxhighlight lang=racket>
#lang racket
(require net/url net/base64)
(base64-encode (call/input-url (string->url "http://rosettacode.org/favicon.ico")
get-pure-port port->bytes))
</syntaxhighlight>
</lang>
Output:
<langsyntaxhighlight lang=racket>
#"AAABAAIAEBAAAAAAAABoBQAA...AQAAAAE=\r\n"
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang=raku perl6line>sub MAIN {
my $buf = slurp("./favicon.ico", :bin);
say buf-to-Base64($buf);
Line 1,736:
else { take '==' }
}
}</langsyntaxhighlight>
{{out}}
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAA...QAAAAEAAAABAAAAAQAAAAE=</pre>
 
=={{header|Red}}==
<langsyntaxhighlight lang=red>Red [Source: https://github.com/vazub/rosetta-red]
 
print enbase read/binary https://rosettacode.org/favicon.ico
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,755:
 
A much higher value for &nbsp; '''chunk''' &nbsp; could be used for modern systems or implementations.
<langsyntaxhighlight lang=rexx>/*REXX program converts text (from a file or the C.L.) to a base64 text string. */
parse arg iFID @ /*obtain optional arguments from the CL*/
if iFID=='' | iFID=="," then iFID='favicon.ico' /*Not specified? Then use the default.*/
Line 1,784:
end /*j*/
/* [↓] maybe append equal signs to $. */
return $ || copies('=', 2 * (L//6==2) + (L//6==4) )</langsyntaxhighlight>
For the various outputs, several input texts from the Wikipedia article on &nbsp; ''Base64'' &nbsp; [http://en.wikipedia.org/wiki/Base64] &nbsp; were used to demonstrate how padding works.
<br><br>
Line 1,824:
 
=={{header|Ring}}==
<langsyntaxhighlight lang=ring>
#=======================================#
# Description : Base64 Sample
Line 1,851:
oQByteArray.append("bXkgc3RyaW5n")
? oQByteArray.fromBase64(oQByteArray).data()
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,859:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang=ruby>require 'open-uri'
require 'base64'
 
puts Base64.encode64 open('http://rosettacode.org/favicon.ico') {|f| f.read}</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight lang=Scala>import java.net.URL
import java.util.Base64
 
Line 1,878:
 
println(s"Successfully completed without errors. [total ${compat.Platform.currentTime - executionStart} ms]")
}</langsyntaxhighlight>
 
=={{header|Seed7}}==
Line 1,885:
which encodes a string with the Base64 encoding.
 
<langsyntaxhighlight lang=seed7>$ include "seed7_05.s7i";
include "gethttp.s7i";
include "encoding.s7i";
Line 1,892:
begin
writeln(toBase64(getHttp("rosettacode.org/favicon.ico")));
end func;</langsyntaxhighlight>
 
=={{header|SenseTalk}}==
<langsyntaxhighlight lang=sensetalk>
put "To err is human, but to really foul things up you need a computer. --Paul R.Ehrlich" as base64
put base64Encode ("To err is human, but to really foul things up you need a computer. --Paul R.Ehrlich")
</syntaxhighlight>
</lang>
Output:
<langsyntaxhighlight lang=sensetalk>
VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVk
IGEgY29tcHV0ZXIuIC0tUGF1bCBSLkVocmxpY2g=
Line 1,906:
VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVk
IGEgY29tcHV0ZXIuIC0tUGF1bCBSLkVocmxpY2g=
</syntaxhighlight>
</lang>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang=ruby>var data = %f'favicon.ico'.read(:raw) # binary string
print data.encode_base64 # print to STDOUT</langsyntaxhighlight>
 
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
<langsyntaxhighlight lang=tcl>package require Tcl 8.6
package require http
 
Line 1,921:
http::cleanup $tok
 
puts [binary encode base64 -maxlen 64 $icondata]</langsyntaxhighlight>
With older versions of Tcl, the base64 encoding is best supported via an external package:
{{tcllib|base64}}
<langsyntaxhighlight lang=tcl>package require base64
package require http
 
Line 1,931:
http::cleanup $tok
 
puts [base64::encode -maxlen 64 $icondata]</langsyntaxhighlight>
 
=={{header|VBA}}==
<langsyntaxhighlight lang=vb>Option Explicit
Public Function Decode(s As String) As String
Dim i As Integer, j As Integer, r As Byte
Line 2,042:
Debug.Print "Result of string comparison of input and decoded output: " & StrComp(In_, bIn, vbBinaryCompare)
Debug.Print "A zero indicates both strings are equal."
End Sub</langsyntaxhighlight>
{{out}}<pre>The first eighty and last eighty characters after encoding:
AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAAAEAB
Line 2,054:
{{libheader|Wren-seq}}
From first principles using string manipulation. Quick enough here.
<langsyntaxhighlight lang=ecmascript>import "io" for File, Stdout
import "/fmt" for Conv, Fmt
import "/seq" for Lst
Line 2,086:
var s = File.read("favicon.ico").bytes.toList
for (chunk in Lst.chunks(s, 3)) encode.call(chunk)
System.print()</langsyntaxhighlight>
 
{{out}}
Line 2,097:
=={{header|zkl}}==
Using shared libraries for cURL and message hashing:
<langsyntaxhighlight lang=zkl>var [const] MsgHash=Import("zklMsgHash"), Curl=Import("zklCurl");
icon:=Curl().get("http://rosettacode.org/favicon.ico"); //-->(Data(4,331),693,0)
Line 2,105:
icon==MsgHash.base64decode(b64));
b64.println();
b64.text.println();</langsyntaxhighlight>
{{out}}
Encoded to 72 characters per line
10,327

edits