示例#1
0
def get_params(source_base, target_base):
    """takes 2 bases, calculate the bit-length they have to be encoded in,
    the common block length both can be encoded in,
    and the amount of symbols contained in that block, for each base"""
    source_width, target_width = [
        getbinlen(len(b) - 1) for b in [source_base, target_base]
    ]  # how many bits necessary to encode a base
    block_width = lcm(source_width, target_width)  # smallest block bit-length to store both

    source_length, target_length = [
        block_width / i for i in [source_width, target_width]
    ]  # how many chars to read to fill a block
    return block_width, source_width, source_length, target_width, target_length
示例#2
0
文件: base.py 项目: stroykova/search
def get_params(source_base, target_base):
    """takes 2 bases, calculate the bit-length they have to be encoded in,
    the common block length both can be encoded in,
    and the amount of symbols contained in that block, for each base"""
    source_width, target_width = [
        getbinlen(len(b) - 1) for b in [source_base, target_base]
    ]  # how many bits necessary to encode a base
    block_width = lcm(source_width,
                      target_width)  # smallest block bit-length to store both

    source_length, target_length = [
        block_width / i for i in [source_width, target_width]
    ]  # how many chars to read to fill a block
    return block_width, source_width, source_length, target_width, target_length
示例#3
0
 gethyphenstr, getlongestcommon, getpadbinstr, getunkbinstr,
 getvaluefrombinarystring, bin2hex, ASCII, as_words,
 hex2bin, insert_string, int2bebin, int2lebin, lcm, md5, modifystring,
 nibbleswap, rol, ror, rorstr, setstr, zip_extend, lcm, slice_and_pad)

import struct

assert char_range("A", "Z") == "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

#gcd
#returns the greatest common divisor of both parameters
assert gcd(6, 8) == 2

#lcm
#returns the least common multiplier of both parameters
assert lcm(6, 9) == 18
assert lcm(6, 8) == 24

assert getbinlen(0) == 1
assert getbinlen(1) == 1
assert getbinlen(3) == 2

assert getvaluefrombinarystring("1000") == 8
assert getvaluefrombinarystring("001000") == 8

assert getpadbinstr(8, 8) == "00001000"

assert getunkbinstr(0, 0, 8) == "000000000"
assert getunkbinstr(1, 0, 8) == "000000001"
assert getunkbinstr(2, 1, 8) == "00000001x"
assert getunkbinstr(237, 3, 8) == "011101xxx"
示例#4
0
                       bin2hex, ASCII, as_words, hex2bin, insert_string,
                       int2bebin, int2lebin, lcm, md5, modifystring,
                       nibbleswap, rol, ror, rorstr, setstr, zip_extend, lcm,
                       slice_and_pad)

import struct

assert char_range("A", "Z") == "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

#gcd
#returns the greatest common divisor of both parameters
assert gcd(6, 8) == 2

#lcm
#returns the least common multiplier of both parameters
assert lcm(6, 9) == 18
assert lcm(6, 8) == 24

assert getbinlen(0) == 1
assert getbinlen(1) == 1
assert getbinlen(3) == 2

assert getvaluefrombinarystring("1000") == 8
assert getvaluefrombinarystring("001000") == 8

assert getpadbinstr(8, 8) == "00001000"

assert getunkbinstr(0, 0, 8) == "000000000"
assert getunkbinstr(1, 0, 8) == "000000001"
assert getunkbinstr(2, 1, 8) == "00000001x"
assert getunkbinstr(237, 3, 8) == "011101xxx"