Sociopunk: text-based steganography
// Sociopunk plaintext steganography module aimed at social network posting | |
// Encoding: Sociopunk.enc(secretText, coverText) when cover text is in Latin | |
// or Sociopunk.enc(secretText, coverText, true) when cover text is in Cyrillic | |
// Decoding: Sociopunk.dec(coverText) or Socipunk.dec(coverText, true) respectively | |
Sociopunk = (function(){ | |
var msg2bin = m => unescape(encodeURIComponent(m)).split('').map(c=>('00000000'+c.charCodeAt(0).toString(2)).substr(-8)).join('').split('').map(Number), | |
bin2msg = b => decodeURIComponent(escape(b.join('').match(/\d{8}/g).map(c => String.fromCharCode(Number('0b'+c))).join(''))), | |
latinPattern = 'aeiocxAEIOCX', cyrPattern = 'аеіосхАЕІОСХ'; | |
return { | |
enc: function(sText, cText, isCyr) { | |
var pi, sBinRep = msg2bin(sText), sLen = sBinRep.length, cLen = cText.length, si=0, ci, outText='', | |
homePattern = isCyr ? cyrPattern : latinPattern, | |
guestPattern = isCyr ? latinPattern : cyrPattern | |
for(ci=0;ci<cLen;ci++) { | |
pi = homePattern.indexOf(cText[ci]) | |
if(pi > -1) { | |
outText += sBinRep[si] === 1 ? guestPattern[pi] : homePattern[pi] | |
si++ | |
} | |
else outText += cText[ci] | |
} | |
return outText | |
}, | |
dec: function(cText, isCyr) { | |
var guestPattern = isCyr ? latinPattern : cyrPattern, | |
seq = cText.match(RegExp('['+cyrPattern+latinPattern+']','g')), | |
outSeq = [], seqLen = seq.length, i; | |
for(i=0;i<seqLen;i++) | |
outSeq.push(guestPattern.indexOf(seq[i]) > -1 ? 1 : 0) | |
return bin2msg(outSeq) | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment