The jsteg Package

Collection of steganography embedding routines for JPEG images.

Module:pysteg.jsteg
Date:$Date: 2010-07-16 10:43:38 +0100 (Fri, 16 Jul 2010) $
Revision:$Revision: 1559 $
Copyright:© 2010: University of Surrey, UK © 2011: Høgskolen i Ålesund, Norway
Author:Hans Georg Schaathun <georg@schaathun.net> (2010-2011)

The abstract stegbase class defines a standard interface for stego-systems. All the other classes provide this interface.

class pysteg.jsteg.f1(L, key=None, rndkey=False, verbosity=1)

Bases: pysteg.jsteg.stegbase.stegbase

The F1 object handles a list of JPEG AC coefficients and embeds and extracts messages using Jsteg.

checknext()

Check that the next coefficient can be used for Jsteg. Move pointer if necessary.

embedAnalysis()

Estimate the embedding capacity.

flipnext()

Flip the message bit in the next position. (Does not proceed to the subsequent bit.)

interpret(y)
class pysteg.jsteg.f3coef(L, key=None, rndkey=False, verbosity=1)

Bases: pysteg.jsteg.f4.f4coef

This object handles a list of JPEG AC coefficients and embeds and extracts messages using F3.

interpret(y)

Decode a coefficient y F3 style. Returns None when y=0.

class pysteg.jsteg.f4coef(L, key=None, rndkey=False, verbosity=1)

Bases: pysteg.jsteg.stegbase.stegbase

The F4 object handles a list of JPEG AC coefficients and embeds and extracts messages using F4.

checknext()

Check that the next coefficient can be used. Move pointer if necessary.

codedim()
codelength()
embedAnalysis()

Estimate the embedding capacity.

embeddingReport()

Print and return quantitative measures of the embedding performance.

f4msgembed_aux(M)

Embed a message using F4 without any status word or length indicator. (Auxiliary function.)

f5capacityreport(i)

Print a report on F5 capacity.

f5embedblock(msg, k=None)

Embed a single F5 block (representing k message bits) at the current position.

f5extract(k=None)

Extract and decode a single block using F5.

f5msgembed(M, k=None)

Embed a complete message including status block, using F5 block. If k=None, an optimal code is chosen based on estimated capacity.

f5msgextract()
flipbit(no=0)

Flip bit no in the current block ignoring all zeros. The next coefficient counter is rewound to the start of the block.

flipnext()

Flip the message bit in the next position. (Does not proceed to the subsequent bit.)

getbit(pad=None)

Extract a single bit using F4.

interpret(y)

Decode a coefficient x F4 style. Returns None when x=0.

msgEmbed(*a, **kw)

Embed a message in the coefficients.

msgExtract(*a, **kw)

Extract a message from the coefficients.

class pysteg.jsteg.f4v2(L, key=None, rndkey=False, verbosity=1)

Bases: pysteg.jsteg.f5.f5v2

getcapacity()
class pysteg.jsteg.f5coef(L, key=None, rndkey=False, verbosity=1)

Bases: pysteg.jsteg.f4.f4coef

The F5 object handles a list of JPEG AC coefficients and embeds and extracts messages using F5.

getcapacity()
class pysteg.jsteg.f5v2(L, key=None, rndkey=False, verbosity=1)

Bases: pysteg.jsteg.f5.f5coef

The F5 object handles a list of JPEG AC coefficients and embeds and extracts messages using F5. This extends the basic F5 class to skip every other pm1. The F5 object also gives full access to F4 methods.

checknext()

Check that the next coefficient can be used. Move pointer if necessary. This method should always be called when the next pointer has been updated, or a coefficient has been changed.

pysteg.jsteg.rndembed(im, msglength, alg, test=False, noreport=False)[source]

Embed a random message of length msglength in image im using algorithm alg. im should be a JPEG object. Note, to embed in random locations, the im object must be prepared for this. The jembed.py script does this correctly.

class pysteg.jsteg.message(random=None, verbosity=1)

Bases: list

A message class for communications systems. It allows getting a bit at a time from a sequence of bytes. Not perfect; it should be extended to work on sequences of other objects, such as int32 or Unicode characters.

drop()

Drop the last byte if zero. It is an error to call this method if the last byte is non-zero. It is used by the extractor when the last byte only contains padding zeros used to fill up the last block.

getbit()

Return the next bit of the messaage. None is returned if there are no remaining bits.

getbits(count=1)

Return the next /count/ bits of the messaage. None is returned if there are no remaining bits.

isequal(other)

Compare the message to another message object or arbitrary list.

length()
putbits(B, N=1)

Insert new bits in the message. Used at the receiver end.

reset()

The F5 Algorithm

Module:pysteg.jsteg.f5
Date:$Date: 2010-07-16 10:43:38 +0100 (Fri, 16 Jul 2010) $
Revision:$Revision: 1559 $
Copyright:© 2009-10: University of Surrey, UK
Author:Hans Georg Schaathun <georg@schaathun.net> (2009-2010)

This module supports steganographic embedding in JPEG using Andreas Westfeld’s F5 algorithm. Two versions are provided. The f5coef class follows Westfeld’s paper and used every non-zero coefficient. The f5v2 class follows Westfeld’s implementation, skiping every other pm1 coefficient.

class pysteg.jsteg.f5.f4v2(L, key=None, rndkey=False, verbosity=1)[source]

Bases: pysteg.jsteg.f5.f5v2

getcapacity()[source]
class pysteg.jsteg.f5.f5coef(L, key=None, rndkey=False, verbosity=1)[source]

Bases: pysteg.jsteg.f4.f4coef

The F5 object handles a list of JPEG AC coefficients and embeds and extracts messages using F5.

getcapacity()[source]
class pysteg.jsteg.f5.f5v2(L, key=None, rndkey=False, verbosity=1)[source]

Bases: pysteg.jsteg.f5.f5coef

The F5 object handles a list of JPEG AC coefficients and embeds and extracts messages using F5. This extends the basic F5 class to skip every other pm1. The F5 object also gives full access to F4 methods.

checknext()[source]

Check that the next coefficient can be used. Move pointer if necessary. This method should always be called when the next pointer has been updated, or a coefficient has been changed.

class pysteg.jsteg.f4.f4coef(L, key=None, rndkey=False, verbosity=1)[source]

Bases: pysteg.jsteg.stegbase.stegbase

The F4 object handles a list of JPEG AC coefficients and embeds and extracts messages using F4.

checknext()[source]

Check that the next coefficient can be used. Move pointer if necessary.

codedim()[source]
codelength()[source]
embedAnalysis()[source]

Estimate the embedding capacity.

embeddingReport()[source]

Print and return quantitative measures of the embedding performance.

f4msgembed_aux(M)[source]

Embed a message using F4 without any status word or length indicator. (Auxiliary function.)

f5capacityreport(i)[source]

Print a report on F5 capacity.

f5embedblock(msg, k=None)[source]

Embed a single F5 block (representing k message bits) at the current position.

f5extract(k=None)[source]

Extract and decode a single block using F5.

f5msgembed(M, k=None)[source]

Embed a complete message including status block, using F5 block. If k=None, an optimal code is chosen based on estimated capacity.

f5msgextract()[source]
flipbit(no=0)[source]

Flip bit no in the current block ignoring all zeros. The next coefficient counter is rewound to the start of the block.

flipnext()[source]

Flip the message bit in the next position. (Does not proceed to the subsequent bit.)

getbit(pad=None)[source]

Extract a single bit using F4.

interpret(y)[source]

Decode a coefficient x F4 style. Returns None when x=0.

msgEmbed(*a, **kw)[source]

Embed a message in the coefficients.

msgExtract(*a, **kw)[source]

Extract a message from the coefficients.

pysteg.jsteg.f4.f4usable(exp, i)[source]

Estimate the number of usable coefficients for F4/F5.

pysteg.jsteg.f4.f5decode(S, n, k=0)[source]

Decode a block using an [n,k] Hamming code as the matrix code. (k is actually ignored in the present version.)

pysteg.jsteg.f4.f5param(exp, msglen)[source]

Calculate code parameters for the matrix code. Returns a pair (n,k).

pysteg.jsteg.f4.getn(k)[source]

F3 should be a simple inheritance from F4, overriding only the interpret function.

class pysteg.jsteg.f3.f3coef(L, key=None, rndkey=False, verbosity=1)[source]

Bases: pysteg.jsteg.f4.f4coef

This object handles a list of JPEG AC coefficients and embeds and extracts messages using F3.

interpret(y)[source]

Decode a coefficient y F3 style. Returns None when y=0.

The JSTEG stego-system.

class pysteg.jsteg.f1.f1(L, key=None, rndkey=False, verbosity=1)[source]

Bases: pysteg.jsteg.stegbase.stegbase

The F1 object handles a list of JPEG AC coefficients and embeds and extracts messages using Jsteg.

checknext()[source]

Check that the next coefficient can be used for Jsteg. Move pointer if necessary.

embedAnalysis()[source]

Estimate the embedding capacity.

flipnext()[source]

Flip the message bit in the next position. (Does not proceed to the subsequent bit.)

interpret(y)[source]
pysteg.jsteg.f1.jstegInterpret(y)[source]

Decode a coefficient x Jsteg style. Returns None when x=0,1.

Auxiliary modules

Definition of exceptions used in the JPEG based steganography classes.

exception pysteg.jsteg.exceptions.CapacityError[source]

Bases: exceptions.RuntimeError

CapacityError indicates a programming error, where the application tries to access beyond the end of the sequence, without having checked for a CapacityException.

exception pysteg.jsteg.exceptions.CapacityException[source]

Bases: exceptions.LookupError

A CapacityException occurs when the file does not have sufficient capacity. This should be considered documented behaviour and should be dealt with.

exception pysteg.jsteg.exceptions.UnusedCoefficientError[source]

Bases: exceptions.LookupError

UnusedCoefficientError occurs when the application attempts to flip a bit which should not be used.

class pysteg.jsteg.message.message(random=None, verbosity=1)[source]

Bases: list

A message class for communications systems. It allows getting a bit at a time from a sequence of bytes. Not perfect; it should be extended to work on sequences of other objects, such as int32 or Unicode characters.

drop()[source]

Drop the last byte if zero. It is an error to call this method if the last byte is non-zero. It is used by the extractor when the last byte only contains padding zeros used to fill up the last block.

getbit()[source]

Return the next bit of the messaage. None is returned if there are no remaining bits.

getbits(count=1)[source]

Return the next /count/ bits of the messaage. None is returned if there are no remaining bits.

isequal(other)[source]

Compare the message to another message object or arbitrary list.

length()[source]
putbits(B, N=1)[source]

Insert new bits in the message. Used at the receiver end.

reset()[source]

Common interface for JPEG steganography classes.

Module:pysteg.jsteg.stegbase
Date:$Date$
Revision:$Revision$
Copyright:© 2010: University of Surrey, UK
Author:Hans Georg Schaathun <georg@schaathun.net> (2010)

The stegbase class is a generic interface for Stego Objects, i.e. multimedia signals with the necessary methods to embed and extract steganographic messages.

Necessary exceptions are defined in the exceptions module. We will also need a Random Number Generator. SystemRandom provides one based on physical events, i.e. potential true randomness.

class pysteg.jsteg.stegbase.stegbase(L, key=None, rndkey=False, verbosity=1)[source]

Bases: list

This is an abstract class, defining key components of the interface of the other JPEG steganography classes.

capacity = None
checknext()[source]

Check that the next coefficient can be used, and move the pointer if necessary. This must be overridden by any child class.

embed(msg, N=32)[source]

Embed N bits. It uses the embedbit() method and rarely requires overriding.

embedAnalysis()[source]

Estimate the embedding capacity. (To be overridden by all children.)

embedbit(msg)[source]

Embed a single bit in the next applicable position. This rarely requires overriding. It uses the interpret() and flipnext() methods, which should be overridden to define the modulation.

embeddingReport()[source]

Print and return quantitative measures of the embedding performance.

flipnext()[source]

Flip the message bit in the next position. (Does not proceed to the subsequent bit.) This must be overridden by any child class.

getbit(pad=None)[source]

Extract a single bit.

This uses the interpret() method, and will rarely need overriding. Instead the interpret() method is overridden.

getcapacity()[source]

Return an estimate of the capacity.

getkey()[source]

Return the key used to encrypt the message.

getword(N=1, pad=0)[source]

Extract N bits.

This uses the getbit() method, and rarely needs overriding.

interpret(y)[source]

Demodulate the given signal sample y. This must be overridden by any child class.

length()[source]

Return the length of the signal, i.e. the total number of coefficients.

msgEmbed(M)[source]

Embed a message, including a status word.

msgExtract()[source]
msgembed_aux(M)[source]

Embed a message using F4 without any status word or length indicator. (Auxiliary function.)

Table Of Contents

Previous topic

Steganographic Embedding

Next topic

The ssteg Package

This Page