steghide  0.5.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
BitString Class Reference

a string of bits More...

#include <BitString.h>

Public Member Functions

 BitString (EmbValue arity=2)
 
 BitString (const BitString &bs)
 
 BitString (const unsigned long l)
 
 BitString (const std::vector< BYTE > &d)
 
 BitString (const std::string &d)
 
void setArity (EmbValue arity)
 
EmbValue getArity (void) const
 
UWORD32 getLength (void) const
 
UWORD32 getNAryLength (void) const
 
BitStringclear (void)
 
BitStringappend (const BIT v)
 
BitStringappend (const BYTE v, const unsigned short n=8)
 
BitStringappend (const UWORD16 v, const unsigned short n=16)
 
BitStringappend (const UWORD32 v, const unsigned short n=32)
 
BitStringappend (const std::string &v)
 
BitStringappend (const std::vector< BYTE > &v)
 
BitStringappend (const BitString &v)
 
BitStringsetBit (unsigned long i, BIT v)
 
BitString getBits (const unsigned long s, const unsigned long l) const
 
BitString cutBits (const unsigned long s, const unsigned long l)
 
UWORD32 getValue (const unsigned long s, const unsigned short l) const
 
const std::vector< BYTE > & getBytes (void) const
 
BitStringtruncate (const unsigned long s, const unsigned long e)
 
BitStringpad (const unsigned long mult, const BIT v)
 
BitStringpadRandom (const unsigned long mult)
 
BYTE getNAry (unsigned long p) const
 
void appendNAry (BYTE v)
 
BIT operator[] (const unsigned long i) const
 
BitStringoperator^= (const BitString &v)
 
bool operator== (const BitString &v) const
 
bool operator!= (const BitString &v) const
 
void print (unsigned short spc=0) const
 

Private Member Functions

void _append (BIT v)
 
void clearUnused (void)
 

Private Attributes

UWORD32 Length
 the number of bits in Data More...
 
EmbValue Arity
 the arity that will be used for getLength/getNAry/appendNAry More...
 
unsigned short ArityNBits
 the number of Bits per n-ary digit (where n is Arity) More...
 
std::vector< BYTEData
 the actual data More...
 

Detailed Description

This class provides a way to conveniently store and manipulate a string of bits. Various objects can be appended to a BitString.

For data storage a vector of BYTEs is used with little endian bit encoding, i.e. the first bit is the least significant bit of the first byte and so on.

Constructor & Destructor Documentation

◆ BitString() [1/5]

BitString::BitString ( EmbValue  arity = 2)

construct an empty BitString

◆ BitString() [2/5]

BitString::BitString ( const BitString bs)

copy constructor

◆ BitString() [3/5]

BitString::BitString ( const unsigned long  l)

construct a BitString containing l bits with value zero

◆ BitString() [4/5]

BitString::BitString ( const std::vector< BYTE > &  d)

construct a BitString containing the data in d

◆ BitString() [5/5]

BitString::BitString ( const std::string &  d)

construct a BitString containing the characters in d as 8 bit unsigned chars

Member Function Documentation

◆ _append()

void BitString::_append ( BIT  v)
private

◆ append() [1/7]

BitString & BitString::append ( const BIT  v)

append the bit v to this BitString

◆ append() [2/7]

BitString & BitString::append ( const BYTE  v,
const unsigned short  n = 8 
)

append n lower order bits of v to this BitString

Parameters
vthe value to be appended
nthe number of bits to be appended

◆ append() [3/7]

BitString & BitString::append ( const UWORD16  v,
const unsigned short  n = 16 
)

append n lower order bits of v to this BitString

Parameters
vthe value to be appended
nthe number of bits to be appended

◆ append() [4/7]

BitString & BitString::append ( const UWORD32  v,
const unsigned short  n = 32 
)

append n lower order bits of v to this BitString

Parameters
vthe value to be appended
nthe number of bits to be appended

◆ append() [5/7]

BitString & BitString::append ( const std::string &  v)

append the string v to this BitString

◆ append() [6/7]

BitString & BitString::append ( const std::vector< BYTE > &  v)

append the vector v byte-wise to this BitString

◆ append() [7/7]

BitString & BitString::append ( const BitString v)

append the BitString v to this BitString

Parameters
vthe BitString to be appended

◆ appendNAry()

void BitString::appendNAry ( BYTE  v)

append an n-ary digit to this BitString

Parameters
vthe n-ary value to be appended

◆ clear()

BitString & BitString::clear ( void  )

delete the contents of this Bitstring

◆ clearUnused()

void BitString::clearUnused ( void  )
private

clear unused part of last byte (_append depends on this)

◆ cutBits()

BitString BitString::cutBits ( const unsigned long  s,
const unsigned long  l 
)

cut some bits out of this BitString

Parameters
sthe index of the first bit to be removed from this BitString
lthe total number of bits to be removed
Returns
the BitString containing of the bits [s...s+(l-1)] of this BitString

After calling cutBits, this BitString consists of the bits 0,...,s-1,s+l,... .

◆ getArity()

EmbValue BitString::getArity ( void  ) const
inline

◆ getBits()

BitString BitString::getBits ( const unsigned long  s,
const unsigned long  l 
) const

get a BitString that is a part of this BitString

Parameters
sthe index of the first bit to be copied from this BitString
lthe total number of bits to be used for the return value
Returns
the BitString containing of the bits [s...s+(l-1)] of this BitString

◆ getBytes()

const std::vector< BYTE > & BitString::getBytes ( void  ) const

get the contents of this BitString as vector of bytes

Returns
the contents of this BitString as vector of bytes

getLength() % 8 must be 0 to call this function

◆ getLength()

UWORD32 BitString::getLength ( void  ) const
inline

get the number of bits in this BitString

◆ getNAry()

BYTE BitString::getNAry ( unsigned long  p) const

get an n-ary digit from this BitString

Parameters
pthe position (in the n-ary representation of this BitString)
Returns
the p-th n-ary digit

◆ getNAryLength()

UWORD32 BitString::getNAryLength ( void  ) const
inline

get the number of EmbValues in this BitString (using this BitString's arity)

◆ getValue()

UWORD32 BitString::getValue ( const unsigned long  s,
const unsigned short  l 
) const

return a value composed from bits in this BitString

Parameters
sthe index of the first bit to be used for the return value
lthe total number of bits to be used for the return value (must be <= 32)
Returns
the value (*this)[s],...,(*this)[s+l-1]

◆ operator!=()

bool BitString::operator!= ( const BitString v) const

compare this BitString with the BitString v

Returns
true iff the lengths are not equal or there exists an index with different values

◆ operator==()

bool BitString::operator== ( const BitString v) const

compare this BitString with the BitString v

Returns
true iff the lengths are equal and for every valid index the value is equal

◆ operator[]()

BIT BitString::operator[] ( const unsigned long  i) const

get the value of the i-th bit

◆ operator^=()

BitString & BitString::operator^= ( const BitString v)

xor v with this BitString, saving the result in this Bitstring. The result has the same length as this BitString.

◆ pad()

BitString & BitString::pad ( const unsigned long  mult,
const BIT  v 
)

pad this BitString with the value in v

Parameters
multthis BitString is padded until size is a multiple of mult (given in bits)
vthe value this BitString should be padded with

◆ padRandom()

BitString & BitString::padRandom ( const unsigned long  mult)

pad this BitString with random data

Parameters
multthis BitString is padded until size is a multiple of mult (given in bits)

◆ print()

void BitString::print ( unsigned short  spc = 0) const

◆ setArity()

void BitString::setArity ( EmbValue  arity)

◆ setBit()

BitString & BitString::setBit ( unsigned long  i,
BIT  v 
)

set the p-th bit to v

Parameters
ithe index (must be < getLength())
vthe value

◆ truncate()

BitString & BitString::truncate ( const unsigned long  s,
const unsigned long  e 
)

truncate this BitString

Parameters
sstart
eend
Returns
this BitString modified to contain only (*this)[s]...(*this)[e - 1]

Member Data Documentation

◆ Arity

EmbValue BitString::Arity
private

◆ ArityNBits

unsigned short BitString::ArityNBits
private

◆ Data

std::vector<BYTE> BitString::Data
private

◆ Length

UWORD32 BitString::Length
private

The documentation for this class was generated from the following files: