Add Bacon cipher encoding

This commit is contained in:
Karsten Silkenbäumer 2019-03-02 17:33:17 +01:00
parent 77b098c5fe
commit a262d70b88
5 changed files with 320 additions and 7 deletions

View file

@ -12,6 +12,7 @@
export const BACON_ALPHABET_REDUCED = "ABCDEFGHIKLMNOPQRSTUWXYZ";
export const BACON_ALPHABET_COMPLETE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
export const BACON_CODES_REDUCED = [0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 23];
export const BACON_TRANSLATION_01 = "0/1";
export const BACON_TRANSLATION_AB = "A/B";
export const BACON_TRANSLATION_CASE = "Case";
@ -22,6 +23,10 @@ export const BACON_TRANSLATIONS = [
BACON_TRANSLATION_CASE,
BACON_TRANSLATION_AMNZ,
];
export const BACON_TRANSLATIONS_FOR_ENCODING = [
BACON_TRANSLATION_01,
BACON_TRANSLATION_AB
];
export const BACON_CLEARER_MAP = {
[BACON_TRANSLATIONS[0]]: /[^01]/g,
[BACON_TRANSLATIONS[1]]: /[^ABab]/g,
@ -35,3 +40,22 @@ export const BACON_NORMALIZE_MAP = {
"b": "1"
},
};
/**
* Swaps zeros to ones and ones to zeros.
*
* @param {string} data
* @returns {string}
*
* @example
* // returns "11001 01010"
* swapZeroAndOne("00110 10101");
*/
export function swapZeroAndOne(string) {
return string.replace(/[01]/g, function (c) {
return {
"0": "1",
"1": "0"
}[c];
});
}