Base64 decode data: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) Rename Perl 6 -> Raku, alphabetize, minor clean-up |
|||
Line 127: | Line 127: | ||
To err is human, but to really foul things up you need a computer. |
To err is human, but to really foul things up you need a computer. |
||
--Paul R.Ehrlich</pre> |
--Paul R.Ehrlich</pre> |
||
=={{header|C#|C_sharp}}== |
|||
{{trans|Visual Basic .NET}} |
|||
<lang csharp>using System; |
|||
using System.Text; |
|||
namespace Base64DecodeData { |
|||
class Program { |
|||
static void Main(string[] args) { |
|||
var data = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g="; |
|||
Console.WriteLine(data); |
|||
Console.WriteLine(); |
|||
var decoded = Encoding.ASCII.GetString(Convert.FromBase64String(data)); |
|||
Console.WriteLine(decoded); |
|||
} |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre>VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g= |
|||
To err is human, but to really foul things up you need a computer. |
|||
-- Paul R. Ehrlich</pre> |
|||
=={{header|C++}}== |
=={{header|C++}}== |
||
Line 257: | Line 280: | ||
To err is human, but to really foul things up you need a computer. |
To err is human, but to really foul things up you need a computer. |
||
--Paul R.Ehrlich</pre> |
--Paul R.Ehrlich</pre> |
||
=={{header|C#|C_sharp}}== |
|||
{{trans|Visual Basic .NET}} |
|||
<lang csharp>using System; |
|||
using System.Text; |
|||
namespace Base64DecodeData { |
|||
class Program { |
|||
static void Main(string[] args) { |
|||
var data = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g="; |
|||
Console.WriteLine(data); |
|||
Console.WriteLine(); |
|||
var decoded = Encoding.ASCII.GetString(Convert.FromBase64String(data)); |
|||
Console.WriteLine(decoded); |
|||
} |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre>VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g= |
|||
To err is human, but to really foul things up you need a computer. |
|||
-- Paul R. Ehrlich</pre> |
|||
=={{header|Caché ObjectScript}}== |
=={{header|Caché ObjectScript}}== |
||
Line 330: | Line 330: | ||
"To err is human, but to really foul things up you need a computer. |
"To err is human, but to really foul things up you need a computer. |
||
-- Paul R. Ehrlich"</pre> |
-- Paul R. Ehrlich"</pre> |
||
=={{header|Factor}}== |
|||
<lang factor>USING: base64 io strings ; |
|||
"VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo" |
|||
base64> >string print</lang> |
|||
{{out}} |
|||
<pre> |
|||
To err is human, but to really foul things up you need a computer. |
|||
--Paul R.Ehrlich |
|||
</pre> |
|||
=={{header|F#}}== |
=={{header|F#}}== |
||
Line 388: | Line 377: | ||
{{out}} |
{{out}} |
||
[https://rosettacode.org/favicon.ico Rosetta Code Icon] |
[https://rosettacode.org/favicon.ico Rosetta Code Icon] |
||
=={{header|Factor}}== |
|||
<lang factor>USING: base64 io strings ; |
|||
"VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo" |
|||
base64> >string print</lang> |
|||
{{out}} |
|||
<pre> |
|||
To err is human, but to really foul things up you need a computer. |
|||
--Paul R.Ehrlich |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 662: | Line 662: | ||
All mimsy were the borogoves, |
All mimsy were the borogoves, |
||
And the mome raths outgrabe.</pre> |
And the mome raths outgrabe.</pre> |
||
=={{header|Perl 6}}== |
|||
{{works with|Rakudo|2018.11}} |
|||
<lang perl6>my $e64 = ' |
|||
VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY2 |
|||
9tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g= |
|||
'; |
|||
my @base64map = flat 'A' .. 'Z', 'a' .. 'z', ^10, '+', '/'; |
|||
my %base64 is default(0) = @base64map.pairs.invert; |
|||
sub base64-decode-slow ($enc) { |
|||
my $buf = Buf.new; |
|||
for $enc.subst(/\s/, '', :g).comb(4) -> $chunck { |
|||
$buf.append: |(sprintf "%06d%06d%06d%06d", |$chunck.comb.map: |
|||
{%base64{$_}.base(2)}).comb(8).map: {:2($_)}; |
|||
} |
|||
$buf |
|||
} |
|||
say 'Slow:'; |
|||
say base64-decode-slow($e64).decode('utf8'); |
|||
# Of course, the above routine is slow and is only for demonstration purposes. |
|||
# For real code you should use a module, which is MUCH faster and heavily tested. |
|||
say "\nFast:"; |
|||
use Base64::Native; |
|||
say base64-decode($e64).decode('utf8');</lang> |
|||
{{out}} |
|||
<pre>Slow: |
|||
To err is human, but to really foul things up you need a computer. |
|||
-- Paul R. Ehrlich |
|||
Fast: |
|||
To err is human, but to really foul things up you need a computer. |
|||
-- Paul R. Ehrlich</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 787: | Line 749: | ||
-- Paul R. Ehrlich |
-- Paul R. Ehrlich |
||
</pre> |
</pre> |
||
=={{header|Raku}}== |
|||
(formerly Perl 6) |
|||
{{works with|Rakudo|2018.11}} |
|||
<lang perl6>my $e64 = ' |
|||
VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY2 |
|||
9tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g= |
|||
'; |
|||
my @base64map = flat 'A' .. 'Z', 'a' .. 'z', ^10, '+', '/'; |
|||
my %base64 is default(0) = @base64map.pairs.invert; |
|||
sub base64-decode-slow ($enc) { |
|||
my $buf = Buf.new; |
|||
for $enc.subst(/\s/, '', :g).comb(4) -> $chunck { |
|||
$buf.append: |(sprintf "%06d%06d%06d%06d", |$chunck.comb.map: |
|||
{%base64{$_}.base(2)}).comb(8).map: {:2($_)}; |
|||
} |
|||
$buf |
|||
} |
|||
say 'Slow:'; |
|||
say base64-decode-slow($e64).decode('utf8'); |
|||
# Of course, the above routine is slow and is only for demonstration purposes. |
|||
# For real code you should use a module, which is MUCH faster and heavily tested. |
|||
say "\nFast:"; |
|||
use Base64::Native; |
|||
say base64-decode($e64).decode('utf8');</lang> |
|||
{{out}} |
|||
<pre>Slow: |
|||
To err is human, but to really foul things up you need a computer. |
|||
-- Paul R. Ehrlich |
|||
Fast: |
|||
To err is human, but to really foul things up you need a computer. |
|||
-- Paul R. Ehrlich</pre> |
|||
=={{header|Red}}== |
=={{header|Red}}== |