steghide  0.5.1
BitString.h
Go to the documentation of this file.
1 /*
2  * steghide 0.5.1 - a steganography program
3  * Copyright (C) 1999-2003 Stefan Hetzl <shetzl@chello.at>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  */
20 
21 #ifndef SH_BITSTRING_H
22 #define SH_BITSTRING_H
23 
24 #include <vector>
25 #include <string>
26 
27 #include "AUtils.h"
28 #include "common.h"
29 
42 class BitString {
43  public:
47  BitString (EmbValue arity = 2) ;
48 
52  BitString (const BitString& bs) ;
53 
57  BitString (const unsigned long l) ;
58 
62  BitString (const std::vector<BYTE>& d) ;
63 
67  BitString (const std::string& d) ;
68 
69  void setArity (EmbValue arity) ;
70 
71  EmbValue getArity (void) const
72  { return Arity ; } ;
73 
77  UWORD32 getLength (void) const
78  { return Length ; } ;
79 
83  UWORD32 getNAryLength (void) const
84  { return AUtils::div_roundup<UWORD32> (Length, ArityNBits) ; } ;
85 
89  BitString& clear (void) ;
90 
94  BitString& append (const BIT v) ;
95 
101  BitString& append (const BYTE v, const unsigned short n = 8) ;
102 
108  BitString& append (const UWORD16 v, const unsigned short n = 16) ;
109 
115  BitString& append (const UWORD32 v, const unsigned short n = 32) ;
116 
120  BitString& append (const std::string& v) ;
121 
125  BitString& append (const std::vector<BYTE>& v) ;
126 
131  BitString& append (const BitString& v) ;
132 
138  BitString& setBit (unsigned long i, BIT v) ;
139 
146  BitString getBits (const unsigned long s, const unsigned long l) const ;
147 
156  BitString cutBits (const unsigned long s, const unsigned long l) ;
157 
164  UWORD32 getValue (const unsigned long s, const unsigned short l) const ;
165 
172  const std::vector<BYTE>& getBytes (void) const ;
173 
180  BitString& truncate (const unsigned long s, const unsigned long e) ;
181 
187  BitString& pad (const unsigned long mult, const BIT v) ;
188 
193  BitString& padRandom (const unsigned long mult) ;
194 
200  BYTE getNAry (unsigned long p) const ;
201 
206  void appendNAry (BYTE v) ;
207 
208 #ifdef USE_ZLIB
209 
216  BitString& compress (int level) ;
217 
231  BitString& uncompress (unsigned long idestlen) ;
232 #endif // def USE_ZLIB
233 
237  BIT operator[] (const unsigned long i) const ;
238 
243  BitString& operator^= (const BitString &v) ;
244 
249  bool operator== (const BitString& v) const ;
250 
255  bool operator!= (const BitString& v) const ;
256 
257  void print (unsigned short spc = 0) const ;
258 #ifdef DEBUG
259  void printDebug (unsigned short level, unsigned short spc = 0) const ;
260 #endif
261 
262  private:
268  unsigned short ArityNBits ;
270  std::vector<BYTE> Data ;
271 
272  void _append (BIT v) ;
273 
277  void clearUnused (void) ;
278 } ;
279 
280 #endif // ndef SH_BITSTRING_H