示例#1
0
def test_bases():
    b36 = base36()
    b52 = base52()
    b56 = base56()
    b58 = base58()
    b62 = base62()
    b94 = base94()
示例#2
0
def get_random_string(CSRF_KEY_LENGTH=128):
    return base56(length=CSRF_KEY_LENGTH).hash(
        randint(0,
                base56(length=CSRF_KEY_LENGTH).maximum))
示例#3
0
def random_key():
    return base56().encode(randint(0, 0xffffffff))
示例#4
0
from nose.tools import raises

from basehash import base56


bh56 = base56()
bh6 = base56(6)
bh10 = base56(10)


def test_base56_encode_with_1234567890_4FXvzC():
    assert bh56.encode(1234567890) == '4FXvzC'


def test_base56_decode_with_4FXvzC_1234567890():
    assert bh56.decode('4FXvzC') == 1234567890


def test_base56_hash_with_1234567890_10_SbTrfJ3VLu():
    assert bh10.hash(1234567890) == 'SbTrfJ3VLu'


def test_base56_unhash_with_SbTrfJ3VLu_1234567890():
    assert bh10.unhash('SbTrfJ3VLu') == 1234567890


def test_base56_maximum_value_with_6_30840979455():
    assert bh6.maximum == 30840979455


@raises(ValueError)
示例#5
0
from basehash import HASH_LENGTH, base36, base52, base56, base58, base62, base94

base36 = base36()
base52 = base52()
base56 = base56()
base58 = base58()
base62 = base62()
base94 = base94()

# Base encode an integer/long
print(base36.encode(200))
print(base52.encode(200))
print(base56.encode(200))
print(base58.encode(200))
print(base62.encode(200))
print(base94.encode(200))

# Base decode encoded string.
print(base36.decode('5K'))
print(base52.decode('3r'))
print(base56.decode('5a'))
print(base58.decode('4T'))
print(base62.decode('3E'))
print(base94.decode('#-'))

# Base hash an integer/long
# Takes an option param, length, which is defaulted to
# basehash.base.HASH_LENGTH
print(base36.hash(200))
print(base52.hash(200))
print(base56.hash(200))
示例#6
0
from nose.tools import raises

from basehash import base56

bh56 = base56()
bh6 = base56(6)
bh10 = base56(10)


def test_base56_encode_with_1234567890_4FXvzC():
    assert bh56.encode(1234567890) == '4FXvzC'


def test_base56_decode_with_4FXvzC_1234567890():
    assert bh56.decode('4FXvzC') == 1234567890


def test_base56_hash_with_1234567890_10_SbTrfJ3VLu():
    assert bh10.hash(1234567890) == 'SbTrfJ3VLu'


def test_base56_unhash_with_SbTrfJ3VLu_1234567890():
    assert bh10.unhash('SbTrfJ3VLu') == 1234567890


def test_base56_maximum_value_with_6_30840979455():
    assert bh6.maximum == 30840979455


@raises(ValueError)
def test_base56_hash_fail_with_30840979456_6():
示例#7
0
from nose.tools import raises

from basehash import base56


base56 = base56()


def test_base56_encode_with_1234567890_4FXvzC():
    assert base56.encode(1234567890) == '4FXvzC'


def test_base56_decode_with_4FXvzC_1234567890():
    assert base56.decode('4FXvzC') == 1234567890


def test_base56_hash_with_1234567890_10_SbTrfJ3VLu():
    assert base56.hash(1234567890, 10) == 'SbTrfJ3VLu'


def test_base56_unhash_with_SbTrfJ3VLu_1234567890():
    assert base56.unhash('SbTrfJ3VLu') == 1234567890


def test_base56_maximum_value_with_6_30840979455():
    assert base56.maximum_value(6) == 30840979455


@raises(ValueError)
def test_base56_hash_fail_with_30840979456_6():
    assert base56.hash(30840979456, 6)
示例#8
0
def get_random_string(CSRF_KEY_LENGTH=128):
    return base56(length=CSRF_KEY_LENGTH).hash(randint(0, base56(length=CSRF_KEY_LENGTH).maximum))
示例#9
0
def random_key():
    return base56().encode(randint(0, 0xffffffff))