This library implements Trytes encoding as described by IOTA project. Trytes are equivalent of bytes but in ternary number system.
Install with composer.
$ composer require tuupola/trytes
$trytes = new Tuupola\Trytes;
$encoded = $trytes->encode(random_bytes(128));
$decoded = $trytes->decode($encoded);
By default this library uses the IOTA style character set. Shortcut is provided also for Heptavintimal characters. If required you can use any custom character set of 27 unique characters.
use Tuupola\Trytes;
print Trytes::IOTA; /* 9ABCDEFGHIJKLMNOPQRSTUVWXYZ */
print Trytes::HEPTAVINTIMAL; /* 0123456789ABCDEFGHKMNPRTVXZ */
$default = new Trytes(["characters" => Trytes::IOTA]);
$heptavintimal = new Trytes(["characters" => Trytes::HEPTAVINTIMAL]);
print $default->encode("Hello world!"); /* RBTC9D9DCDEAKDCDFD9DSCFA */
print $heptavintimal->encode("Hello world!"); /* K2N304043451B4346404M361 */
If you prefer to use static syntax use the provided static proxy.
use Tuupola\TrytesProxy as Trytes;
$encoded = Trytes::encode(random_bytes(128));
$decoded = Trytes::decode($encoded);
You can run tests either manually or automatically on every code change. Automatic tests require entr to work.
$ make test
$ brew install entr
$ make watch
Please see CONTRIBUTING for details.
If you discover any security related issues, please email tuupola@appelsiini.net instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.