How would you rotate numbers in string using a rotational cypher?

78 Views Asked by At

Hello I'm trying to solve the classic rotational cypher problem but im also trying to solve for when numbers are included in the string. So far this is the method I have been going about it using javascript:

function rotationalCipher(input, rotationFactor) {

const originalAlpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

return input.replace(/[a-z]/gi, letter => originalAlpha[originalAlpha.indexOf(letter)+rotationFactor]);
  

}

It works but it doesn't address the numbers within the string. Id be appreciative of any help.

0

There are 0 best solutions below