From 1b4591dcbe1367eb6b1858cec49df620147be360 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Thu, 8 Sep 2011 12:27:40 +0000 Subject: [PATCH] improved steganography functions --- demos/image/js/image.js | 2 +- source/Ox.Image/Ox.Image.js | 30 +++++++++++++++++++----------- source/Ox.UI/js/Form/Ox.Filter.js | 29 +++++++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/demos/image/js/image.js b/demos/image/js/image.js index 53125a2d..30d8e0ff 100644 --- a/demos/image/js/image.js +++ b/demos/image/js/image.js @@ -13,7 +13,7 @@ Ox.load('Image', function() { 'encode("some secret stuff")', 'decode()', 'encode("some secret stuff", true)', 'decode(true)', 'encode("some secret stuff", 1)', 'decode(1)', - 'encode("some secret stuff", 127)', 'decode(127)', + 'encode("some secret stuff.", 15)', 'decode(15)', 'hue(-60)', 'hue(60)', 'invert()', 'lightness(-0.5)', 'lightness(0.5)', diff --git a/source/Ox.Image/Ox.Image.js b/source/Ox.Image/Ox.Image.js index 9c35f78c..bb1db90d 100644 --- a/source/Ox.Image/Ox.Image.js +++ b/source/Ox.Image/Ox.Image.js @@ -27,7 +27,7 @@ Ox.load.Image = function(options, callback) { function getCapacity(bpb) { var capacity = 0; that.forEach(function(rgba) { - capacity += rgba[3] == 255 ? bpb / 8 : 0; + capacity += rgba[3] == 255 ? bpb * 3/8 : 0; }); return capacity; } @@ -167,21 +167,29 @@ Ox.load.Image = function(options, callback) { var i = index + c; Ox.forEach(bits, function(bit) { if (mode < 1) { - bin += Ox.sum(Ox.range(8).map(function(b) { - return self.data[i] & 1 << b; + bin += Ox.sum(Ox.range(8).map(function(bit) { + return +!!(self.data[i] & 1 << bit); })) % 2; } else { - bin += +!!(self.data[i] & i << bit); + bin += +!!(self.data[i] & 1 << bit); } - /*mode > 0 &&*/ Ox.print(bin) + // /*mode > 0 &&*/ Ox.print(bin) if (bin.length == 8) { str += Ox.char(parseInt(bin, 2)); bin = ''; if (str.length == len) { if (++done == 1) { len = Ox.decodeBase256(str); - Ox.print("LEN", len) - if (len + 4 > getCapacity(1)) { + Ox.print(Ox.map(str, function(chr) { + return Ox.pad(chr.charCodeAt(0).toString(2), 8); + }).join(' ')) + Ox.print("LEN", len, getCapacity(bits.length), bits, xy, c) + Ox.print(Ox.range(index).map(function(i) { + return that.pixel(i, 0).map(function(px, j) { + return j < 4 ? Ox.pad(px.toString(2), 8) : null; + }).join(',') + }).join('\n')) + if (len + 4 > getCapacity(bits.length)) { error('decode'); } str = ''; @@ -250,16 +258,16 @@ Ox.load.Image = function(options, callback) { mode < 1 // If the number of bits set to 1, mod 2 ? Ox.sum(Ox.range(8).map(function(bit) { - return self.data[i] & 1 << bit; + return +!!(self.data[i] & 1 << bit); })) % 2 // or the one bit in question - : self.data[i] & 1 << bit + : +!!(self.data[i] & 1 << bit) // is not equal to the data bit ) != bin[b++]) { // then flip the bit self.data[i] ^= 1 << bit; } - }) + }); /* if (mode < 1) { if (Ox.sum(Ox.range(8).map(function(bit) { @@ -406,7 +414,7 @@ Ox.load.Image = function(options, callback) { }; that.pixel = function(x, y, val) { - var index = getIndex(x, y); + var i = getIndex(x, y); if (!val) { return Ox.range(4).map(function(c) { return self.data[i + c]; diff --git a/source/Ox.UI/js/Form/Ox.Filter.js b/source/Ox.UI/js/Form/Ox.Filter.js index 84cdd9c4..bbc96055 100644 --- a/source/Ox.UI/js/Form/Ox.Filter.js +++ b/source/Ox.UI/js/Form/Ox.Filter.js @@ -110,6 +110,7 @@ Ox.Filter = function(options, self) { float: 'left', }); + Ox.print('s.o.sK', self.options.sortKeys) self.$limit = Ox.InputGroup({ inputs: [ Ox.Checkbox({ @@ -138,6 +139,11 @@ Ox.Filter = function(options, self) { width: 120 }), Ox.Select({ + /* + items: self.options.sortKeys.map(function(sortKey) { + return {id: sortKey.id, title: sortKey.title[0]}; // fixme: title should not have become an array + }), + */ items: self.options.sortKeys, width: 128 }), @@ -182,6 +188,25 @@ Ox.Filter = function(options, self) { ] }); + /* + // fixme: sortKeys have been altered, probably by some select + Ox.print('s.o.sK', self.options.sortKeys) + self.$sort = Ox.InputGroup({ + inputs: [ + Ox.Checkbox({ + width: 16 + }), + Ox.Select({ + items: self.options.sortKeys, + width: 128 + }) + ], + separators: [ + {title: 'By default, sort by', width: 112} + ] + }); + */ + self.$save = Ox.InputGroup({ inputs: [ Ox.Checkbox({ @@ -197,7 +222,7 @@ Ox.Filter = function(options, self) { ] }); - self.$items = [self.$operator, self.$limit, self.$view, self.$save]; + self.$items = [self.$operator, self.$limit, self.$view/*, self.$sort*/, self.$save]; self.$form = Ox.Form({ items: self.$items @@ -237,7 +262,7 @@ Ox.Filter = function(options, self) { oldType = Ox.getObjectById(self.options.findKeys, condition.key).type, newType = Ox.getObjectById(self.options.findKeys, key).type, oldConditionType = getConditionType(oldType), - newConditionType = getConditionType(newType); + newConditionType = getConditionType(newType), changeConditionType = oldConditionType != newConditionType; Ox.print('old new', oldConditionType, newConditionType) condition.key = key;