Пример #1
0
def interleaved_gamma_encode(value):
    binary = getbinstr(value)
    remaining_bits = binary[1:]
    result = str()
    for i, c in enumerate(remaining_bits):
        result += remaining_bits[i]
        is_last_bit = (i == len(remaining_bits) - 1)
        result += "0" if not is_last_bit else "1"
    return result
Пример #2
0
def interleaved_gamma_encode(value):
    binary = getbinstr(value)
    remaining_bits = binary[1:]
    result = str()
    for i, c in enumerate(remaining_bits):
        result += remaining_bits[i]
        is_last_bit = (i == len(remaining_bits) - 1)
        result += "0" if not is_last_bit else "1"
    return result
Пример #3
0
def omega_encode(value, first_step=True):
    if first_step == True:
        string = omega_encode(value, first_step=False) + "0"
    else:
        if value == 1:
            return str()
        else:
            encoding = getbinstr(value)
            width = len(encoding)
            string =  omega_encode(width - 1, first_step=False) + encoding
    return string
Пример #4
0
def omega_encode(value, first_step=True):
    if first_step == True:
        string = omega_encode(value, first_step=False) + "0"
    else:
        if value == 1:
            return str()
        else:
            encoding = getbinstr(value)
            width = len(encoding)
            string = omega_encode(width - 1, first_step=False) + encoding
    return string
Пример #5
0
def elias_split(value):
    binary = getbinstr(value)
    highest_bit = len(binary) - 1
    remaining_bits = binary[1:]
    return highest_bit, remaining_bits
Пример #6
0
def elias_split(value):
    binary = getbinstr(value)
    highest_bit = len(binary) - 1
    remaining_bits = binary[1:]
    return highest_bit, remaining_bits
Пример #7
0
assert rol(0x1234567800, 8, 32) == 0x56780034 # entry value is masked first
assert rol(0x12345678, 8, 64) == 0x1234567800

assert ror(0x12345678, 8, 32) == 0x78123456
assert ror(0x12345678, 8, 64) == 0x7800000000123456

assert byteswap(0x12345678, 4) == 0x78563412
assert byteswap(0x12345678, 2) == 0x7856    #incorrect use but expected result

assert nibbleswap(0x1234, 2) == 0x2143



assert gethyphenstr(r"c:\WINDOWS\system32\drivers\http.sys") == r"c:\WINDOW [...] \http.sys"

assert getbinstr(0) == "0"
assert getbinstr(8) == "1000"

assert countmissing(0, 8) == 0
assert countmissing(3, 8) == 5
assert countmissing(8, 8) == 0

assert insert_string("abcd", 2, "1") == "ab1cd"

assert zip([1, 2], [0]) == [(1, 0)]
assert zip_extend([1, 2], [0], 0) == [(1, 0), (2, 0)]
assert zip_extend([0], [1, 2], 0) == [(1, 0), (2, 0)]

assert rorstr("abc") == "cab"
assert [rorstr("abc", i) for i in range(4)] == ['abc', 'cab', 'bca', 'abc']
Пример #8
0
assert rol(0x12345678, 8, 32) == 0x34567812
assert rol(0x1234567800, 8, 32) == 0x56780034  # entry value is masked first
assert rol(0x12345678, 8, 64) == 0x1234567800

assert ror(0x12345678, 8, 32) == 0x78123456
assert ror(0x12345678, 8, 64) == 0x7800000000123456

assert byteswap(0x12345678, 4) == 0x78563412
assert byteswap(0x12345678, 2) == 0x7856  #incorrect use but expected result

assert nibbleswap(0x1234, 2) == 0x2143

assert gethyphenstr(
    r"c:\WINDOWS\system32\drivers\http.sys") == r"c:\WINDOW [...] \http.sys"

assert getbinstr(0) == "0"
assert getbinstr(8) == "1000"

assert countmissing(0, 8) == 0
assert countmissing(3, 8) == 5
assert countmissing(8, 8) == 0

assert insert_string("abcd", 2, "1") == "ab1cd"

assert zip([1, 2], [0]) == [(1, 0)]
assert zip_extend([1, 2], [0], 0) == [(1, 0), (2, 0)]
assert zip_extend([0], [1, 2], 0) == [(1, 0), (2, 0)]

assert rorstr("abc") == "cab"
assert [rorstr("abc", i) for i in range(4)] == ['abc', 'cab', 'bca', 'abc']