Skip to content

Instantly share code, notes, and snippets.

@lepinekong
Created December 25, 2017 17:48
Show Gist options
  • Save lepinekong/c9f5c5203cbfdaee2b5d337809f2b151 to your computer and use it in GitHub Desktop.
Save lepinekong/c9f5c5203cbfdaee2b5d337809f2b151 to your computer and use it in GitHub Desktop.
base58 by @9214
unfold: function [spec][
to string! collect [
repeat i length? bitset: charset spec [
if bitset/:i [keep to char! i]
]
]
]
to-base58: function [string][
base58: rejoin [
exclude unfold [#"0" - #"9"] "0"
exclude unfold [#"A" - #"Z"] "IO"
exclude unfold [#"a" - #"z"] "l"
]
acc: 0
repeat i length: length? string [
index: length - i
factor: 2.0 ** (index * 8)
acc: acc + multiply to float! string/:i factor
]
to string! collect [
foreach index reverse collect [
until [
probe acc
keep add to integer! probe (acc % 58) 1
zero? round acc: acc / 58
]
][
keep base58/:index
]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment