Skip to content
Advertisement

Why is my decryption function not working?

I created a function to encrypt and decrypt messages. the encrypting works fine. but when I try to log encrypted Hello World! it just logs H.

JavaScript

Fixed it, i edited the encoding system to place a – between chars and the decoding system to just split the message at – and check if the element starts with c n or s. and then i just used substring to get the number and decrypt it

JavaScript

Advertisement

Answer

You need to split the encoded string based on set/index pairs. This is easy enough to do with a look-ahead regular expression and splitting before a c, n or an s. /(?=[cns])/

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement