From 0b98201b9670e61a0018427b87ba3c77cad3f9f8 Mon Sep 17 00:00:00 2001 From: chedulurivijayakumar <85997231+chedulurivijayakumar@users.noreply.github.com> Date: Wed, 24 Nov 2021 17:51:06 +1100 Subject: [PATCH] Update substitution.coffee --- 08-cipher/lib/substitution.coffee | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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 = ''