improved steganography functions
This commit is contained in:
parent
3f3edac8c7
commit
1b4591dcbe
3 changed files with 47 additions and 14 deletions
|
@ -13,7 +13,7 @@ Ox.load('Image', function() {
|
||||||
'encode("some secret stuff")', 'decode()',
|
'encode("some secret stuff")', 'decode()',
|
||||||
'encode("some secret stuff", true)', 'decode(true)',
|
'encode("some secret stuff", true)', 'decode(true)',
|
||||||
'encode("some secret stuff", 1)', 'decode(1)',
|
'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)',
|
'hue(-60)', 'hue(60)',
|
||||||
'invert()',
|
'invert()',
|
||||||
'lightness(-0.5)', 'lightness(0.5)',
|
'lightness(-0.5)', 'lightness(0.5)',
|
||||||
|
|
|
@ -27,7 +27,7 @@ Ox.load.Image = function(options, callback) {
|
||||||
function getCapacity(bpb) {
|
function getCapacity(bpb) {
|
||||||
var capacity = 0;
|
var capacity = 0;
|
||||||
that.forEach(function(rgba) {
|
that.forEach(function(rgba) {
|
||||||
capacity += rgba[3] == 255 ? bpb / 8 : 0;
|
capacity += rgba[3] == 255 ? bpb * 3/8 : 0;
|
||||||
});
|
});
|
||||||
return capacity;
|
return capacity;
|
||||||
}
|
}
|
||||||
|
@ -167,21 +167,29 @@ Ox.load.Image = function(options, callback) {
|
||||||
var i = index + c;
|
var i = index + c;
|
||||||
Ox.forEach(bits, function(bit) {
|
Ox.forEach(bits, function(bit) {
|
||||||
if (mode < 1) {
|
if (mode < 1) {
|
||||||
bin += Ox.sum(Ox.range(8).map(function(b) {
|
bin += Ox.sum(Ox.range(8).map(function(bit) {
|
||||||
return self.data[i] & 1 << b;
|
return +!!(self.data[i] & 1 << bit);
|
||||||
})) % 2;
|
})) % 2;
|
||||||
} else {
|
} 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) {
|
if (bin.length == 8) {
|
||||||
str += Ox.char(parseInt(bin, 2));
|
str += Ox.char(parseInt(bin, 2));
|
||||||
bin = '';
|
bin = '';
|
||||||
if (str.length == len) {
|
if (str.length == len) {
|
||||||
if (++done == 1) {
|
if (++done == 1) {
|
||||||
len = Ox.decodeBase256(str);
|
len = Ox.decodeBase256(str);
|
||||||
Ox.print("LEN", len)
|
Ox.print(Ox.map(str, function(chr) {
|
||||||
if (len + 4 > getCapacity(1)) {
|
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');
|
error('decode');
|
||||||
}
|
}
|
||||||
str = '';
|
str = '';
|
||||||
|
@ -250,16 +258,16 @@ Ox.load.Image = function(options, callback) {
|
||||||
mode < 1
|
mode < 1
|
||||||
// If the number of bits set to 1, mod 2
|
// If the number of bits set to 1, mod 2
|
||||||
? Ox.sum(Ox.range(8).map(function(bit) {
|
? Ox.sum(Ox.range(8).map(function(bit) {
|
||||||
return self.data[i] & 1 << bit;
|
return +!!(self.data[i] & 1 << bit);
|
||||||
})) % 2
|
})) % 2
|
||||||
// or the one bit in question
|
// or the one bit in question
|
||||||
: self.data[i] & 1 << bit
|
: +!!(self.data[i] & 1 << bit)
|
||||||
// is not equal to the data bit
|
// is not equal to the data bit
|
||||||
) != bin[b++]) {
|
) != bin[b++]) {
|
||||||
// then flip the bit
|
// then flip the bit
|
||||||
self.data[i] ^= 1 << bit;
|
self.data[i] ^= 1 << bit;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
/*
|
/*
|
||||||
if (mode < 1) {
|
if (mode < 1) {
|
||||||
if (Ox.sum(Ox.range(8).map(function(bit) {
|
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) {
|
that.pixel = function(x, y, val) {
|
||||||
var index = getIndex(x, y);
|
var i = getIndex(x, y);
|
||||||
if (!val) {
|
if (!val) {
|
||||||
return Ox.range(4).map(function(c) {
|
return Ox.range(4).map(function(c) {
|
||||||
return self.data[i + c];
|
return self.data[i + c];
|
||||||
|
|
|
@ -110,6 +110,7 @@ Ox.Filter = function(options, self) {
|
||||||
float: 'left',
|
float: 'left',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Ox.print('s.o.sK', self.options.sortKeys)
|
||||||
self.$limit = Ox.InputGroup({
|
self.$limit = Ox.InputGroup({
|
||||||
inputs: [
|
inputs: [
|
||||||
Ox.Checkbox({
|
Ox.Checkbox({
|
||||||
|
@ -138,6 +139,11 @@ Ox.Filter = function(options, self) {
|
||||||
width: 120
|
width: 120
|
||||||
}),
|
}),
|
||||||
Ox.Select({
|
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,
|
items: self.options.sortKeys,
|
||||||
width: 128
|
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({
|
self.$save = Ox.InputGroup({
|
||||||
inputs: [
|
inputs: [
|
||||||
Ox.Checkbox({
|
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({
|
self.$form = Ox.Form({
|
||||||
items: self.$items
|
items: self.$items
|
||||||
|
@ -237,7 +262,7 @@ Ox.Filter = function(options, self) {
|
||||||
oldType = Ox.getObjectById(self.options.findKeys, condition.key).type,
|
oldType = Ox.getObjectById(self.options.findKeys, condition.key).type,
|
||||||
newType = Ox.getObjectById(self.options.findKeys, key).type,
|
newType = Ox.getObjectById(self.options.findKeys, key).type,
|
||||||
oldConditionType = getConditionType(oldType),
|
oldConditionType = getConditionType(oldType),
|
||||||
newConditionType = getConditionType(newType);
|
newConditionType = getConditionType(newType),
|
||||||
changeConditionType = oldConditionType != newConditionType;
|
changeConditionType = oldConditionType != newConditionType;
|
||||||
Ox.print('old new', oldConditionType, newConditionType)
|
Ox.print('old new', oldConditionType, newConditionType)
|
||||||
condition.key = key;
|
condition.key = key;
|
||||||
|
|
Loading…
Reference in a new issue