forked from 0x2620/oxjs
improved steganography functions
This commit is contained in:
parent
3f3edac8c7
commit
1b4591dcbe
3 changed files with 47 additions and 14 deletions
|
|
@ -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];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue