reshadman/bijective-shortener

此包最新版本(1.0)没有可用的许可信息。

PHP的干净双向基数转换器

1.0 2015-03-15 09:07 UTC

This package is auto-updated.

Last update: 2024-09-12 07:06:59 UTC


README

此包是一个双向短码器,可以将您的唯一整数标识符(如mysql自增键)缩短为唯一的短字符串。该策略简单地将数字转换为更大的基数。

使用方法

您可以通过设置要包含到缩短字符串中的字符来指定您想要的字符,默认设置为随机字符串。请注意,这不仅仅是一个加密解决方案,而是一个编码解决方案,类似于base_64,但在更大的基数上,通过制作随机排序的允许字符,您可以保证在给定缩短字符串的情况下无法猜测到一个长数字。

<?php
use \Reshadman\BijectiveShortener\BijectiveShortener;

BijectiveShortener::setChars(
    'YRCAtS2qcL06JzFeWIsf9HbwgVPUoOkrZpaGm47vjNEuMT1dynlDxXhQK8i5B3'
);

$shortened = BijectiveShortener::makeFromInteger($int = 60500);

$decoded = BijectiveShortener::decodeToInteger($shortened);

echo 'The Shortened version of ' . $int ' is' . $shortened '\n';
echo 'The decoded version of ' . $shortened ' is ' . $decoded ' which is equal to original number(' . $int ')';