Base64 decode data: Difference between revisions

no edit summary
(Added Racket solution)
No edit summary
Line 1,293:
To err is human, but to really foul things up you need a computer.
--Paul R.Ehrlich</pre>
 
=={{header|M2000 Interpreter}}==
 
=====Using a file and a Document object=====
Load.doc handle automatic UTF16LE UTF16BE UTF8 and ANSI. Also automatic find the type of new line (here is LF)
 
Tempname$ retuen a unique path+filename at temporary folder. The temporary file automatic deleted when the M2000 environment closed.
 
<syntaxhighlight lang="m2000 interpreter">
inp$={VG8gZXJyIGlzIGh1bWFuLCBidXQ
gdG8gcmVhbGx5IGZvdWwgdGhpbmdzI
HVwIHlvdSBuZWVkIGEgY29tcHV0ZXI
uCiAgICAtLSBQYXVsIFIuIEVocmxpY2g=
}
tmp$=tempname$
open tmp$ for wide output as #f
print #f, string$(inp$ as decode64);
close #f
document a$
load.doc a$, tmp$
report a$
clipboard a$
</syntaxhighlight>
 
=====Without File=====
If we now the encoding and type of line feed we can do this:
 
<syntaxhighlight lang="m2000 interpreter">
inp$={VG8gZXJyIGlzIGh1bWFuLCBidXQ
gdG8gcmVhbGx5IGZvdWwgdGhpbmdzI
HVwIHlvdSBuZWVkIGEgY29tcHV0ZXI
uCiAgICAtLSBQYXVsIFIuIEVocmxpY2g=
}
// decode inp$ (is 8-bit ANSI coded using 0xA for paragraph end/new line)
a$=string$(inp$ as Decode64)
locale 1033
// convert ansi to utf16le using Locale 1033
a$=chr$(a$) // convert to utf16LE
// expand LF to CRLF for M2000 console
a$=replace$(chr$(0xA), chr$(0XD)+chr$(0XA), a$)
// report handle cr and lf using proportional spacing for text and auto word wrapping
report a$
// also Print channel #-2 handle cr and lf (using non proportional spacing)
print #-2, a$
</syntaxhighlight>
 
{{out}}
<pre>
To err is human, but to really foul things up you need a computer.
-- Paul R. Ehrlich
</pre>
 
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
404

edits