Skip to main content

No project description provided

Project description

bitsbehumble

BitsBeHumble is a lightweight type converter python library. it is designed to make CTF scripting a wee bit easier. Its main purpose is to save you the googling time you spend every time you need to convert from one type to another, convert endianness or simply convert a binary array to a binary string.

It doesn't support unicode, yet.

>>> string_to_hex('Hello World!',end='little')
>>> 0x21646c726f57206f6c6c6548

>>> binary_to_string('0100100001100101011011000110110001101111')
>>> Hello

>>> little_to_big_endian(0x21646c726f57206f6c6c6548)
>>> 0x48656c6c6f20576f726c6421

>>> hex_to_binary('0x48656c6c6f20576f726c64',ret='list')
>>> ['0b1001000', '0b1100101', '0b1101100', '0b1101100', '0b1101111', '0b100000', '0b1010111', '0b1101111', '0b1110010', '0b1101100', '0b1100100']

Installation

pip install bitsbehumble


Contribution

Pull requests , Ideas and feedback are welcomed.

Documentation

Naming convetion: type_to_type().

Default return type: same type as the first argument unless specified otherwise.

Available return types :ret='list', ret='int' , ret='str'.

Default Endianness: big-endian Available Endianness: end='big' , end='little'

All functions accept all 3 types of arguments ( int, str, list ) with or without prefixes ('0x' , '0b') unless specified otherwise in the function name, for example:

binstr_to_binarray(bin_str)  
binarray_to_binstr(bin_arr)
string_to_binary(string, ret='default')
hexstring_to_array(hex_str)
hexarr_to_hexstring(hex_array)
string_to_hex(string ,end='big',ret='str') 

Available Functions

hex_to_binary(hx,ret='default')

params: hx(any type) ret (str): 'int', 'str' or 'list'

default return type: (same as hx)

binary_to_hex(b,ret='default')

params: b (any type) ret (str): 'int', 'str' or 'list'

default return type: (same as b)

hex_to_string(hx)

can also be called like this: unhexlify(hx) params: hx (any type)

default return type: (str)

binary_to_string(b):

params: b (any type)

default return type: (str)

string_to_binary(string, ret='default')

params: string (str) ret (str): 'int', 'str' or 'list'

default return type: (same as string)

string_to_hex(string ,end='big',ret='str')

can also be called like this: hexlify(string ,end='big',ret='str')

params: string (str) end (str) : 'big' or 'little' ret (str): 'int', 'str' or 'list'

default return type: (str)

little_to_big_endian(hx,ret='default')

params: hx (any type) ret (str): 'int', 'str' or 'list'

default return type: (same as hx)

big_to_little_endian(hx,ret='default')

params: hx (any type) ret (str): 'int', 'str' or 'list'

default return type: (same as hx)

zero_extend(b,n,at='start')

works like python's zfill.

for binary strings: extends them to a length divisible by 8 if (n) isn't specified. if n is specified it adds (n) zeros to the start or the end of the string.

for strings: does nothing if (n) isn't specified. if n is specified it adds (n) zeros to the start or the end of the string.

params: b (string) n (int) at (str) 'start' or 'end'

default return type: (string)

hexarr_to_hexstring(hex_array)

params: hex_array (list)

default return type: (str)

binstr_to_binarray(bin_str)

params: bin_str (str)

default return type: (list)

binarray_to_binstr(bin_arr)

params: bin_arr (list)

default return type: (str)

to_binstr(b)

takes a binary of any type and returns a binary string

params: b (any type)

default return type: (str)

string_to_bytes(string,ret='default')

params: string (str) ret (str): 'int', 'str' or 'list'

default return type: (same as string)

bytes_to_string(b)

params: b (any type) : str , int , bytes, bytearray or list of any type.

default return type: (str)

hexstring_to_array(hex_str):

params: hex_str (string)

default return type: (list)

to_hexstr(hx)

takes a hex int/str/bytes/list/bytearray and returns the string representation of it

params: hx (any type)

default return type: (str)

hex_to_bytes(hx)

params: hx (any type)

default return type: (bytes)

is_valid_hex(hx)

params: hx (any type)

default return type: (bool)

is_valid_binary(b)

params: b (any type)

default return type: (bool)

getKey(dct,value)

searches a given dictionary for the key of the given value and returns a list of one or more keys

params: dct (dict) value (any type)

default return type: (list)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bitsbehumble-0.6.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file bitsbehumble-0.6.tar.gz.

File metadata

  • Download URL: bitsbehumble-0.6.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.6.9

File hashes

Hashes for bitsbehumble-0.6.tar.gz
Algorithm Hash digest
SHA256 d99e5374034ea3413e75da06b0cd9836566ecb2210a725a8b06f70c40fec5460
MD5 c24b6abfd6279af18e54298daefba507
BLAKE2b-256 ea8f81a4a7c8bcf5735f22a9416aac6f3155a3b6910f64900d034e15f8e85c57

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page