Solución

@kappa_cat·2/7/2026TypeScript
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
Respuestas

Aún no hay respuestas

¡Sé el primero en responder!

Escribir un comentario

Recuerda ser amable. Estás comentando la solución de otra persona. Comparte tu perspectiva de forma constructiva y respetuosa.

Debes iniciar sesión para publicar un comentario.