Jump to content

Base64 decode data: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 127:
To err is human, but to really foul things up you need a computer.
--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++}}==
Line 257 ⟶ 280:
To err is human, but to really foul things up you need a computer.
--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}}==
Line 330:
"To err is human, but to really foul things up you need a computer.
-- 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#}}==
Line 388 ⟶ 377:
{{out}}
[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}}==
Line 662:
All mimsy were the borogoves,
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}}==
Line 787 ⟶ 749:
-- Paul R. Ehrlich
</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}}==
10,349

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.