Created
January 16, 2024 18:54
-
-
Save berdfandrade/4fbc54bf8e53227faeb7bb986a51814d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function transformString(str) { | |
let transformed = ""; | |
for (let i = 0; i < str.length; i++) { | |
let letter = str[i]; | |
if (/[a-zA-Z]/.test(letter)) { | |
let ascii = letter.charCodeAt(0); | |
ascii += 13; | |
if ((ascii > 122) || (ascii > 90)) { | |
ascii -= 26; | |
} | |
transformed += String.fromCharCode(ascii); | |
} else { | |
transformed += letter; | |
} | |
} | |
return transformed; | |
} | |
function rot13(str) { | |
let arr = [str]; | |
console.log(arr); | |
let newArr = []; | |
let novo; | |
for(let i = 0; i < arr.length; i++){ | |
for(let j = 0; j < arr[i].length; j++){ | |
newArr.push(transformString(arr[i][j])) | |
} | |
} | |
novo = newArr.join("") | |
console.log(novo) | |
return novo | |
} | |
rot13("SERR CVMMN!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment