From 9c18eaf3855dfc44189638e7ec4914892f6f4d2f Mon Sep 17 00:00:00 2001 From: xarsman Date: Tue, 12 Aug 2014 17:40:42 +0200 Subject: [PATCH] baconjs now decodes hidden bacon code BaCoN's cIphEr or THE bacOnIAN CiPHer iS a meThOD oF sTEGaNOGrapHY (a METhoD Of HidIng A sECRet MeSsaGe as OpPOsEd TO a TRUe CiPHeR) dEVIseD BY francis bAcoN. a MessAge Is coNCeALED decodes into V E R YX W EL LXD O NE X F E L L O W X H A C KE RX --- bacon/vendor/bacon.js | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/bacon/vendor/bacon.js b/bacon/vendor/bacon.js index 1720bc8..16ff223 100644 --- a/bacon/vendor/bacon.js +++ b/bacon/vendor/bacon.js @@ -20,18 +20,49 @@ var DEFAULT_ALPHABET = 'ABCDEFGHIKLMNOPQRSTUWXYZ'; var decode = function(ciphertext, options) { - ciphertext = ciphertext.toUpperCase(); - // Use the most common 24-letter Bacon alphabet by default. + // the baconcode is hidden in the ciphertext (eg uppercase = 'A' and lowercase = 'B') var alphabet = options && options.alphabet != null ? options.alphabet.toUpperCase() : DEFAULT_ALPHABET; - var index = -1; + var index = 0; var length = ciphertext.length; + var symbol; + var alphabetIndex; + symbol = ciphertext.charAt(0); + // x is for aB and X for Ab + if (symbol == 'x'){ + while (++index < length) { + alphabetIndex = alphabet.indexOf(ciphertext.charAt(index).toUpperCase()); + if (alphabetIndex > -1) { + symbol = ciphertext.charAt(index); + if (symbol == symbol.toUpperCase()){ + ciphertext = ciphertext.substring(0, index) + 'B' + ciphertext.substring(index + 1); + } else { + ciphertext = ciphertext.substring(0, index) + 'A' + ciphertext.substring(index + 1); + } + } + } + } + else if (symbol == 'X'){ + while (++index < length) { + alphabetIndex = alphabet.indexOf(ciphertext.charAt(index).toUpperCase()); + if (alphabetIndex > -1) { + symbol = ciphertext.charAt(index); + if (symbol == symbol.toUpperCase()){ + ciphertext = ciphertext.substring(0, index) + 'A' + ciphertext.substring(index + 1); + } else { + ciphertext = ciphertext.substring(0, index) + 'B' + ciphertext.substring(index + 1); + } + } + } + } + // continue normal decoding + ciphertext = ciphertext.toUpperCase(); + // Use the most common 24-letter Bacon alphabet by default. + index = -1; var space = ''; var result = ''; var buffer = []; - var symbol; - var alphabetIndex; while (++index < length) { symbol = ciphertext.charAt(index); if (symbol == 'A' || symbol == 'B') {