base64_encode / decodeに似たエンコーディング/デコーディング関数を知っている人はいますが、base64は時々=を出力するため、数字や文字のみを出力します。これは私のコードを台無しにします。ありがとう
2761 次
2 に答える
1
Base64 is not encryption. I'd suggest you learn aboutwhat encryption means. But anyway, it sounds like what you want is Base32 encoding. In Python, you can get it just by doing
base64.b32encode(data)
Edit: base32 encoding also uses = to pad by default, but if it is causing a problem, you can simply omit the padding.
base64.b32encode(data).rstrip('=')
于 2012-07-28T13:42:59.370 に答える
0
これは私が書いたowncloudアプリ用に作成したアルゴリズムです。あなたはあなた自身のアルファベットを指定することができるので、それは試してみる価値があるかもしれません。実装はphpですが、簡単に移植できます。
/**
* @method randomAlphabet
* @brief Creates a random alphabet, unique but static for an installation
* @access public
* @author Christian Reiner
*/
static function randomAlphabet ($length)
{
if ( ! is_integer($length) )
return FALSE;
$c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxwz0123456789";
return substr ( str_shuffle($c), 0, $length );
} // function randomAlphabet
/**
* @method OC_Shorty_Tools::convertToAlphabet
* @brief Converts a given decimal number into an arbitrary base (alphabet)
* @param integer number: Decimal numeric value to be converted
* @return string: Converted value in string notation
* @access public
* @author Christian Reiner
*/
static function convertToAlphabet ( $number, $alphabet )
{
$alphabetLen = strlen($alphabet);
if ( is_numeric($number) )
$decVal = $number;
else throw new OC_Shorty_Exception ( "non numerical timestamp value: '%1'", array($number) );
$number = FALSE;
$nslen = 0;
$pos = 1;
while ($decVal > 0)
{
$valPerChar = pow($alphabetLen, $pos);
$curChar = floor($decVal / $valPerChar);
if ($curChar >= $alphabetLen)
{
$pos++;
} else {
$decVal -= ($curChar * $valPerChar);
if ($number === FALSE)
{
$number = str_repeat($alphabet{1}, $pos);
$nslen = $pos;
}
$number = substr($number, 0, ($nslen - $pos)) . $alphabet{(int)$curChar} . substr($number, (($nslen - $pos) + 1));
$pos--;
}
}
if ($number === FALSE) $number = $alphabet{1};
return $number;
}
于 2012-07-28T13:45:47.400 に答える