Base58Check encoding: Difference between revisions

Added example for D
m (spelt the names of the four characters that aren't in the default base58 alphabet.)
(Added example for D)
Line 90:
0xecac89cad93923c02321 --> EJDM8drfXA6uyA
0x10c8511e --> Rt5zm</pre>
 
=={{header|D}}==
<lang D>import std.bigint;
import std.stdio;
 
void main() {
report("25420294593250030202636073700053352635053786165627414518");
report(0x61);
report(0x626262);
report(0x636363);
report("0x73696d706c792061206c6f6e6720737472696e67");
report(0x516b6fcd0f);
report("0xbf4f89001e670274dd");
report(0x572e4794);
report("0xecac89cad93923c02321");
report(0x10c8511e);
}
 
void report(T)(T v) {
import std.traits;
static if (isIntegral!T) {
enum format = "%#56x -> %s";
} else {
enum format = "%56s -> %s";
}
writefln(format, v, v.toBase58);
}
 
string toBase58(T)(T input) {
import std.traits;
static if (isSomeString!T) {
return toBase58(BigInt(input));
} else {
import std.algorithm.mutation : reverse;
import std.array : appender;
enum ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
 
auto sb = appender!(char[]);
size_t mod;
 
do {
mod = cast(size_t) (input % ALPHABET.length);
sb.put(ALPHABET[mod]);
 
input /= ALPHABET.length;
} while (input);
 
sb.data.reverse;
return sb.data.idup;
}
}</lang>
{{out}}
<pre>25420294593250030202636073700053352635053786165627414518 -> 6UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM
0x61 -> 2g
0x626262 -> a3gV
0x636363 -> aPEr
0x73696d706c792061206c6f6e6720737472696e67 -> 2cFupjhnEsSn59qHXstmK2ffpLv2
0x516b6fcd0f -> ABnLTmg
0xbf4f89001e670274dd -> 3SEo3LWLoPntC
0x572e4794 -> 3EFU7m
0xecac89cad93923c02321 -> EJDM8drfXA6uyA
0x10c8511e -> Rt5zm</pre>
 
=={{header|Haskell}}==
<lang haskell>import Numeric (showIntAtBase)
1,452

edits