Commit 033d3b0dcd2e935089ea680a551c49f3cd01d2bb
1 parent
6cbb3879
Exists in
master
staged.
Showing
7 changed files
with
39 additions
and
35 deletions
Show diff stats
msteg/StegBase.py
| ... | ... | @@ -20,7 +20,7 @@ class StegBase(object): |
| 20 | 20 | similarly such as JSteg, OutGuess and F3. |
| 21 | 21 | """ |
| 22 | 22 | |
| 23 | - def __init__(self): | |
| 23 | + def __init__(self,key=sample_key): | |
| 24 | 24 | """ |
| 25 | 25 | Constructor of the JPEGSteg class. |
| 26 | 26 | """ |
| ... | ... | @@ -28,7 +28,7 @@ class StegBase(object): |
| 28 | 28 | self.cov_jpeg = None |
| 29 | 29 | self.cov_data = None |
| 30 | 30 | self.hid_data = None |
| 31 | - self.key = None | |
| 31 | + self.key = key | |
| 32 | 32 | |
| 33 | 33 | def _get_cov_data(self, img_path): |
| 34 | 34 | """ |
| ... | ... | @@ -143,6 +143,14 @@ class StegBase(object): |
| 143 | 143 | (emb_size, verb, duration, (emb_size / duration) / 1000., |
| 144 | 144 | float(emb_size) / cov_size)) |
| 145 | 145 | |
| 146 | + # set & get | |
| 147 | + def set_key(self, key): | |
| 148 | + assert key != None | |
| 149 | + self.key = key | |
| 150 | + | |
| 151 | + def get_key(self): | |
| 152 | + return self.key | |
| 153 | + | |
| 146 | 154 | # dummy functions to please pylint |
| 147 | 155 | def _raw_embed(self, cov_data, hid_data): |
| 148 | 156 | pass | ... | ... |
msteg/StegBase.pyc
No preview for this file type
msteg/steganography/F4.py
| ... | ... | @@ -18,8 +18,7 @@ class F4(StegBase): |
| 18 | 18 | """ |
| 19 | 19 | Constructor of the F3 class. |
| 20 | 20 | """ |
| 21 | - StegBase.__init__(self) | |
| 22 | - self.key = key | |
| 21 | + StegBase.__init__(self, key) | |
| 23 | 22 | |
| 24 | 23 | def _get_cov_data(self, img_path): |
| 25 | 24 | """ |
| ... | ... | @@ -76,7 +75,6 @@ class F4(StegBase): |
| 76 | 75 | header_size = 4 * 8 |
| 77 | 76 | size_data, bits_cnt = self._raw_extract(steg_data, header_size) |
| 78 | 77 | size_data = bits2bytes(size_data) |
| 79 | - print size_data | |
| 80 | 78 | |
| 81 | 79 | size_hd = 0 |
| 82 | 80 | for i in xrange(4): |
| ... | ... | @@ -144,4 +142,4 @@ class F4(StegBase): |
| 144 | 142 | return hid_data, j |
| 145 | 143 | |
| 146 | 144 | def __str__(self): |
| 147 | - return "F4'" | |
| 145 | + return "F4" | ... | ... |
msteg/steganography/F4.pyc
No preview for this file type
msteg/steganography/F5.py
| ... | ... | @@ -22,27 +22,25 @@ which embedding function (one of JSteg, F3, F4) should be used. |
| 22 | 22 | import time |
| 23 | 23 | import math |
| 24 | 24 | import numpy as np |
| 25 | -from stegotool.plugins.steganography.F4.F4 import F4 | |
| 26 | -from stegotool.util.JPEGSteg import JPEGSteg | |
| 27 | -from stegotool.util.plugins import describe_annotate_convert | |
| 28 | -from stegotool.util.plugins import ident, ImagePath, FilePath, NewFilePath | |
| 25 | +import numpy.random as rnd | |
| 26 | +from msteg.StegBase import * | |
| 27 | +from F4 import F4 | |
| 28 | +import mjsteg | |
| 29 | +import jpegObj | |
| 30 | +from common import * | |
| 29 | 31 | |
| 30 | 32 | |
| 31 | -class F5(JPEGSteg): | |
| 33 | +class F5(StegBase): | |
| 32 | 34 | """ This module has two methods: <i>embed_raw_data</i> to embed data |
| 33 | 35 | with the F5 algorithm and <i>extract_raw_data</i> to extract data |
| 34 | 36 | which was embedded previously. """ |
| 35 | 37 | |
| 36 | - def __init__(self, ui, core): | |
| 38 | + def __init__(self, key=sample_key): | |
| 37 | 39 | """ |
| 38 | 40 | Constructor of the F5 class. |
| 39 | 41 | """ |
| 40 | - JPEGSteg.__init__(self, ui, core) | |
| 41 | - self._embed_hook = self._embed_k | |
| 42 | - self._extract_hook = self._extract_k | |
| 42 | + StegBase.__init__(self, key) | |
| 43 | 43 | self._embed_fun = None |
| 44 | - self.dct_p = None | |
| 45 | - self.seed = None | |
| 46 | 44 | self.default_embedding = True |
| 47 | 45 | self.steg_ind = -1 |
| 48 | 46 | self.excess_bits = None |
| ... | ... | @@ -56,7 +54,7 @@ class F5(JPEGSteg): |
| 56 | 54 | ("stego image", NewFilePath, str), |
| 57 | 55 | ("seed", int, int), |
| 58 | 56 | ("embedding behavior", |
| 59 | - ['Default', 'F3', 'JSteg'], str)) | |
| 57 | + ['Default', 'F3', 'JSteg'], str)) | |
| 60 | 58 | def embed_raw_data(self, src_cover, src_hidden, tgt_stego, seed, |
| 61 | 59 | embed_fun): |
| 62 | 60 | """<p>This method embeds arbitrary data into a cover image. |
| ... | ... | @@ -162,7 +160,7 @@ class F5(JPEGSteg): |
| 162 | 160 | while not success: |
| 163 | 161 | self.cov_ind += 1 |
| 164 | 162 | while cov_data[self.dct_p[self.cov_ind]] == 0 or \ |
| 165 | - self.dct_p[self.cov_ind] % 64 == 0: | |
| 163 | + self.dct_p[self.cov_ind] % 64 == 0: | |
| 166 | 164 | self.cov_ind += 1 |
| 167 | 165 | if m != cov_data[self.dct_p[self.cov_ind]] & 1: |
| 168 | 166 | cov_data[self.dct_p[self.cov_ind]] -= \ |
| ... | ... | @@ -176,8 +174,8 @@ class F5(JPEGSteg): |
| 176 | 174 | k_split = np.zeros(4, np.uint8) |
| 177 | 175 | for i in xrange(k_split.size): |
| 178 | 176 | self.steg_ind += 1 |
| 179 | - while self.steg_data[self.dct_p[self.steg_ind]] == 0 or\ | |
| 180 | - self.dct_p[self.steg_ind] % 64 == 0: | |
| 177 | + while self.steg_data[self.dct_p[self.steg_ind]] == 0 or \ | |
| 178 | + self.dct_p[self.steg_ind] % 64 == 0: | |
| 181 | 179 | self.steg_ind += 1 |
| 182 | 180 | k_split[i] = self.steg_data[self.dct_p[self.steg_ind]] & 1 |
| 183 | 181 | self.k_coeff = self.lookup_tab.merge_words(tuple([0, 0, 0, 0] + |
| ... | ... | @@ -190,7 +188,7 @@ class F5(JPEGSteg): |
| 190 | 188 | for i, c in enumerate(cov_data): |
| 191 | 189 | if update_cnt == 0: |
| 192 | 190 | self._set_progress( |
| 193 | - int(30 * (float(i) / float(cov_data.size)))) | |
| 191 | + int(30 * (float(i) / float(cov_data.size)))) | |
| 194 | 192 | update_cnt = 10000 |
| 195 | 193 | update_cnt -= 1 |
| 196 | 194 | # pessimistic, but accurate estimation of the capacity of the image |
| ... | ... | @@ -204,7 +202,7 @@ class F5(JPEGSteg): |
| 204 | 202 | raise Exception("Cannot fit %d bits in %d DCT coefficients. \ |
| 205 | 203 | Cover image is too small." % (hid_size, cov_size)) |
| 206 | 204 | self.ui.display_status('DCT embedding ratio = %f' \ |
| 207 | - % (float(hid_size) / float(cov_size))) | |
| 205 | + % (float(hid_size) / float(cov_size))) | |
| 208 | 206 | k = 1 |
| 209 | 207 | while True: |
| 210 | 208 | k += 1 |
| ... | ... | @@ -246,14 +244,14 @@ class F5(JPEGSteg): |
| 246 | 244 | while remaining_bits > 0: |
| 247 | 245 | if update_cnt == 0: |
| 248 | 246 | self._set_progress(30 + int((( |
| 249 | - hid_size - remaining_bits) / hid_size) * 70)) | |
| 247 | + hid_size - remaining_bits) / hid_size) * 70)) | |
| 250 | 248 | update_cnt = int(hid_size / (70.0 * k)) |
| 251 | 249 | update_cnt -= 1 |
| 252 | 250 | msg_chunk_size = min(remaining_bits, k) |
| 253 | 251 | msg_chunk = np.zeros(k, np.int8) |
| 254 | 252 | cov_chunk = np.zeros(n, np.int32) |
| 255 | 253 | msg_chunk[0:msg_chunk_size] = hid_data[hid_ind:hid_ind + |
| 256 | - msg_chunk_size] | |
| 254 | + msg_chunk_size] | |
| 257 | 255 | hid_ind += k |
| 258 | 256 | |
| 259 | 257 | # get n DCT coefficients |
| ... | ... | @@ -281,8 +279,8 @@ class F5(JPEGSteg): |
| 281 | 279 | if cov_data[cov_chunk[s - 1]] == 0: # test for shrinkage |
| 282 | 280 | cov_chunk[s - 1:-1] = cov_chunk[s:] # adjusting |
| 283 | 281 | cov_ind += 1 |
| 284 | - while cov_data[dct_p[cov_ind]] == 0 or\ | |
| 285 | - dct_p[cov_ind] % 64 == 0: | |
| 282 | + while cov_data[dct_p[cov_ind]] == 0 or \ | |
| 283 | + dct_p[cov_ind] % 64 == 0: | |
| 286 | 284 | cov_ind += 1 |
| 287 | 285 | cov_chunk[n - 1] = dct_p[cov_ind] |
| 288 | 286 | else: |
| ... | ... | @@ -319,7 +317,7 @@ class F5(JPEGSteg): |
| 319 | 317 | |
| 320 | 318 | if self.excess_bits != None: |
| 321 | 319 | hid_data[hid_ind:hid_ind + self.excess_bits.size] = \ |
| 322 | - self.excess_bits | |
| 320 | + self.excess_bits | |
| 323 | 321 | hid_ind += self.excess_bits.size |
| 324 | 322 | remaining_bits -= self.excess_bits.size |
| 325 | 323 | |
| ... | ... | @@ -331,7 +329,7 @@ class F5(JPEGSteg): |
| 331 | 329 | |
| 332 | 330 | if update_cnt == 0 and not is_header: |
| 333 | 331 | self._set_progress(int(((float(num_bits) \ |
| 334 | - - remaining_bits) / num_bits) * 100)) | |
| 332 | + - remaining_bits) / num_bits) * 100)) | |
| 335 | 333 | update_cnt = int(num_bits / (100.0 * k)) |
| 336 | 334 | |
| 337 | 335 | update_cnt -= 1 |
| ... | ... | @@ -339,8 +337,8 @@ class F5(JPEGSteg): |
| 339 | 337 | steg_chunk = [0 for i in xrange(n)] |
| 340 | 338 | for i in xrange(n): |
| 341 | 339 | self.steg_ind += 1 |
| 342 | - while self.steg_data[dct_p[self.steg_ind]] == 0 or\ | |
| 343 | - dct_p[self.steg_ind] % 64 == 0: | |
| 340 | + while self.steg_data[dct_p[self.steg_ind]] == 0 or \ | |
| 341 | + dct_p[self.steg_ind] % 64 == 0: | |
| 344 | 342 | self.steg_ind += 1 |
| 345 | 343 | steg_chunk[i] = self.steg_data[dct_p[self.steg_ind]] |
| 346 | 344 | ... | ... |
test_jpeg.py
| ... | ... | @@ -187,11 +187,11 @@ if __name__ == '__main__': |
| 187 | 187 | # test_bitbyte() |
| 188 | 188 | |
| 189 | 189 | ima = jpegObj.Jpeg("res/test3.jpg",key=sample_key) |
| 190 | - imb = jpegObj.Jpeg("res/new.jpg",key=sample_key) | |
| 190 | + # imb = jpegObj.Jpeg("res/new.jpg",key=sample_key) | |
| 191 | 191 | imc = jpegObj.Jpeg("res/steged.jpg",key=sample_key) |
| 192 | 192 | print ima.Jgetcompdim(0) |
| 193 | - print ima.getkey(),imb.getkey() | |
| 194 | - diffblocks(imb, ima) | |
| 193 | + print ima.getkey(),imc.getkey() | |
| 194 | + diffblocks(ima, imc) | |
| 195 | 195 | |
| 196 | 196 | # c1 = ima.getCoefBlocks() |
| 197 | 197 | # c2 = imb.getCoefBlocks() | ... | ... |
test_steg.py