All encryption methods have a corresponding inverse. The inverse can be used for decryption. This is why the
decrypt function simply encrypts the data with the inverse operation.
Each encryption method is just a different way of combining 2 numbers. Encryption functions are passed c1
and c2 and should return c3. Inverse functions should return c1 when passed c3 and c2.
Encryption methods can be selected by name using JezzaMeakoEncryption.setMethod
and passing the
name of the desired method.
The built-in encryption methods are as follows:
add/subtract Uses addition and subtraction to merge character codes, respectively
multiply/divide Uses multiplication and division to merge character codes, respectively
super/unsuper Uses multiplication and addition, and division and subtraction, respectively
To add custom methods, use JezzaMeakoEncryption.registerMethod
and pass it an object containing
a method and, optionally, an inverse. The method and inverse objects MUST have a name (string) and a
function (function). The function is passed c1 and c2 (inverse functions should consider c1 equivalent to c3
and vice-versa). When an inverse function is not provided, the default method is set as the inverse,
rendering the JezzaMeakoEncryption.decrypt
defective.
Jeremy = new JezzaMeakoEncryption();
Jeremy.setMethod('super');
Jeremy.encrypt('Happy Birthday Jeremy', 'my secret key'); // 'ἕ⹒ภ㋃〢ೃᷖ⧒㐜ຠ⯣⟙⹒㏲ྙॠⷒⵟ❲ー〢'
Jeremy.decrypt('ἕ⹒ภ㋃〢ೃᷖ⧒㐜ຠ⯣⟙⹒㏲ྙॠⷒⵟ❲ー〢', 'my secret key'); // 'Happy Birthday Jeremy'
Jeremy.registerMethod({ // Adds a custom method and inverse equivalent to super and unsuper but additions and subtractions are swapped
method: {
name: 'superAlt',
function: (c1, c2) => c1 * c2 - c2
},
inverse: {
name: 'unsuperAlt',
function: (c1, c2) => (c1 + c2) / c2
}
});
Jeremy.setMethod('superAlt');
Jeremy.encrypt('Jeremy is cool', 'birthday'); // '᯲⤄㉒ⵐ⯠⻠ிㄨ⮤ಷ⮤㇘Ⲱ⧌'
Jeremy.decrypt('᯲⤄㉒ⵐ⯠⻠ிㄨ⮤ಷ⮤㇘Ⲱ⧌', 'birthday'); // 'Jeremy is cool'
Jeremy.setMethod('unsuperAlt');
Jeremy.encrypt('᯲⤄㉒ⵐ⯠⻠ிㄨ⮤ಷ⮤㇘Ⲱ⧌', 'birthday'); // 'Jeremy is cool'
Jeremy.decrypt('᯲⤄㉒ⵐ⯠⻠ிㄨ⮤ಷ⮤㇘Ⲱ⧌', 'birthday'); // '뉂툻栒蟌튘伜狾㭯둦㚦準镬✘卌'