diff --git a/08-cipher/lib/substitution.coffee b/08-cipher/lib/substitution.coffee index 66867e1..b4d9a6e 100644 --- a/08-cipher/lib/substitution.coffee +++ b/08-cipher/lib/substitution.coffee @@ -4,11 +4,23 @@ alphabet1 = 'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ' exports.encrypt = (string) -> - # - # !!! Place your solition here !!! - # - return 'fix me' +const crypto = require('crypto'); +const algorithm = 'aes-256-ctr'; +const secretKey = 'vOVH6sdmpNWjRRIqCc7rdxs01lwHzfr3'; +const iv = crypto.randomBytes(16); + +const encrypt = (text) => { + + const cipher = crypto.createCipheriv(algorithm, secretKey, iv); + + const encrypted = Buffer.concat([cipher.update(text), cipher.final()]); + + return { + iv: iv.toString('hex'), + content: encrypted.toString('hex') + }; +}; exports.decrypt = (string) -> result = ''