mattallty / base58 Goto Github PK
View Code? Open in Web Editor NEWBase58 encoder/decoder in PHP
License: MIT License
Base58 encoder/decoder in PHP
License: MIT License
>>> \Allty\Utils\Base58::encode(\Allty\Utils\Base58::decode('jrGwppJ4WSr'))
=> "jrGwppJ4XYr"
Here are some more examples for you:
https://gist.github.com/amcsi/0f9a14f6d9aec185e9e2a41d7f786b44
The script as it stands with the following:
static $alphabet = '23456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
const BASE = 58;
I ran a test of sequential numbers and here is what I found.
$i : encode($i) => decode(encode($i))
0 : => 0 // ERROR
1 : 3 => 1
2 : 4 => 2
3 : 5 => 3
4 : 6 => 4
.
.
.
57 : => 0 // ERROR
.
.
114 : 3Z => 114
115 : 3 => 1 // ERROR
116 : 42 => 116
.
.
172 : 4Z => 17
173 : 4 => 2 // ERROR
174 : 52 => 174
Here are my observations:
Changing to BASE 56 works but doing so will work but you could not encode 0 and Z would never be used
0 : => 0 // ERROR
1 : 3 => 1
2 : 4 => 2
.
.
54 : X => 54
55 : Y => 55
56 : 32 => 56 // Z is never used
57 : 33 => 57
.
.
110 : 3X => 110
111 : 3Y => 111 // Z is never used
112 : 42 => 112
113 : 43 => 113
Im using simpletest to run these numbers
while($i < 1000)
{
$this->assertEqual($i, Base58::decode(Base58::encode($i)));
echo '<br>' . $i . ' : ' . Base58::encode($i) . ' => ' . Base58::decode(Base58::encode($i));
$i++;
}
In the documentation you state
... Base-58 contains alphanumeric characters minus "1" (number 1) ...
However looking at the $alphabet value I see the number 1.
static $alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.