Skip to content

Commit

Permalink
Merge pull request #5 from jjsullivan5196/gh-pages
Browse files Browse the repository at this point in the history
Channel auto select/detect
  • Loading branch information
jjsullivan5196 committed Dec 14, 2015
2 parents e406992 + c871b9a commit f04385b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<script type="text/javascript" src="js/mime.js"></script>
<script type="text/javascript" src="js/bloburl.js"></script>
<script type="text/javascript" src="js/functions.js"></script>
<script type="text/javascript" src="js/magic.js"></script>
<script type="text/javascript" src="js/stego.js"></script>
</head>
<body>
Expand Down Expand Up @@ -40,7 +41,7 @@
<button class="btn btn-primary" id="stegoInject" type="button" >Inject</button>
<button class="btn btn-primary" id="stegoRetrieve" type="button">Retrieve</button>
</div>
<input class="form-control" id="xthPixel" type="number" size="1" maxlength="2" value="3" min="3" max="20"/>
<input class="form-control" id="xthPixel" type="number" size="1" maxlength="2" value="2" min="2" max="20"/>
</div>
<br>
<a id="stegoFile" href="" download=""></a>
Expand Down
72 changes: 72 additions & 0 deletions js/magic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
function determineBestChannel(fileSize, imageX, imageY)
{
var s = 0;
for(var x = 4; x <= imageX * imageY; x++)
{
if(x%2 == 0)
{
s++;
}
}
if(s < fileSize)
{
return -1;
}
var best = 2;//max
for (var x = 3; x <= 20; x++)
{
var next = ((imageX*imageY) - 3) / x;
if(next > fileSize)
{
best = x;
}
else
{
break;
}
}
return best;
}

function scanXth(data)
{
for (var xth = 2; xth <= 20; xth++)// in range(2, 21):
{
//console.log("--------------------------------------------------------------------")
//prvar("Checking channel " + str(xth))
var arr = new Array();
for(var i = 4; arr.length < 300; i++) {
if(xthPattern(i, xth)) {
var baseColor = avgColor(getPixel(data, (i-1)), getPixel(data, (i+1))),
dataColor = retrieveColor(getPixel(data, i), baseColor, 7),
inData = rgbaToVal(dataColor, 7);
arr.push(inData);
}
}
//Split off the non-filename component
try{
//////////////Filename Length Validity Check////////////
if(arr[0] > 300 || arr[0] < 1)
{
throw "Filename Too Long or too short" + arr[0];
}
//////////////////////////////////////////////////////////////////////////////////////
rawName = arr.slice(1, arr[0] + 1)
////////////////Filename Prvarability Check////////////////
for(var i = 0; i < rawName.length; i++)
{
if(rawName[i] < 32 || rawName[i] > 126)
{
throw "Unprintable character";
}
}
//////////////////////////////////////////////////////////////////////////////////////
return (xth)
}catch(e)
{
//console.log(e)
continue
}
}
return (0)
}
4 changes: 4 additions & 0 deletions js/stego.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ function inject(ev) {

if(link.href) URL.revokeObjectURL(link.href);

if(xth < 3) xth = determineBestChannel(byteNum, canvas.width, canvas.height);

reader.onload = function(e) {
var fileCont = Array.from(new Uint8Array(e.target.result)),
fileName = [file.name.length];
Expand Down Expand Up @@ -98,6 +100,8 @@ function retrieve(ev) {
col2 = retrieveColor(getPixel(data, 1),getPixel(data, 3),10),
col3 = retrieveColor(getPixel(data, 2),getPixel(data, 3),10),
byteNum = (rgbaToVal(col3, 10)*1000000) + (rgbaToVal(col2, 10)*1000) + rgbaToVal(col1, 10);

if(xth < 3) xth = scanXth(data);

for(var i = 4; buffer.length < byteNum; i++) {
if(xthPattern(i, xth)) {
Expand Down
3 changes: 2 additions & 1 deletion js/titler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ function titler() {
"Use any image of the President for a surprise.",
"Why are you here?",
"We don't negotiate with terrorists.",
"Your packets have been diverted, consequences will never be the same."
"Your packets have been diverted, consequences will never be the same.",
"Nobody cared what the file was until you hid it."
];
document.title = "Steganosaurus: " + titleArray[parseInt(Math.random() * titleArray.length)];
}

0 comments on commit f04385b

Please sign in to comment.