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