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 everytime you need to convert from one type to another, convert endianness or simply convert a binary array to a binary string.

It doesnt support unicode, yet. Contribution and pull requests are welcomed.

>>> 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 default return type: same type as the first argument unless specified otherwise.

Available return types are: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)
zero_extend(bin_str)
is_valid_hex(hx)
is_invalid_binary(b)
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(bin_str)

works like python's zfill.

params: bin_str (string)

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)

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 or bytes or list of any type

default return type: (str)

hexstring_to_array(hex_str):

params: hex_str (string)

default return type: (list)

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_invalid_binary(b)

params: b (string)

default return type: (bool)

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.5.tar.gz (5.0 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: bitsbehumble-0.5.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

File hashes

Hashes for bitsbehumble-0.5.tar.gz
Algorithm Hash digest
SHA256 91645796e22b767ab81959c4601f31a4fb8ddc78fed0b52cfd0574781ef58231
MD5 b88cc22602471400603d3aff316647f8
BLAKE2b-256 86304b9bb240825813edaeb2ac3c9630f3bb875754f6ce7d0cda35c12d4ddce4

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