Solución
solution.tsTypeScript
export function vigenereEncrypt(text: string, key: string): string {
let result = ''
let keyIndex = 0
for (const char of text) {
if (!/[a-zA-Z]/.test(char)) {
result += char
continue
}
const keyOffset = key.toLowerCase().charCodeAt(keyIndex % key.length) - 97
const code = char.charCodeAt(0)
// ASCII: 'A-Z' = 65-90, 'a-z' = 97-122
const base = code >= 65 && code <= 90 ? 65 : 97 // start for alphabet range
result += String.fromCharCode(
((code - base + keyOffset) % 26) + base
)
keyIndex++
}
return result;
}0respuestas