Jump to content

Base64 decode data: Difference between revisions

Added Wren
(Added Wren)
Line 1,213:
To err is human, but to really foul things up you need a computer.
-- Paul R. Ehrlich</pre>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
{{libheader|Wren-str}}
From first principles using string manipulation. Quick enough here.
<lang ecmascript>import "io" for Stdout
import "/fmt" for Conv, Fmt
import "/str" for Str
 
var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
 
var decode = Fn.new { |s|
if (s == "") return s
var d = ""
for (b in s) {
var ix = alpha.indexOf(b)
if (ix >= 0) d = d + Fmt.swrite("$06b", ix)
}
if (s.endsWith("==")) {
d = d[0..-5]
} else if (s.endsWith("=")){
d = d[0..-3]
}
var i = 0
while (i < d.count) {
var ch = String.fromByte(Conv.atoi(d[i..i+7], 2))
System.write(ch)
i = i + 8
}
Stdout.flush()
}
 
var s = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g="
for (chunk in Str.chunks(s, 4)) decode.call(chunk)
System.print()</lang>
 
{{out}}
<pre>
To err is human, but to really foul things up you need a computer.
-- Paul R. Ehrlich
</pre>
 
=={{header|zkl}}==
9,492

edits

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