Welcome to Cipher Solutions' most elite encryption service: Superior Vigenère! This is where the pros come to play.
// Vigenère cipher implementation in JavaScript
function vigenere_cipher(text, key) {
let alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let cipher_text = '';
let key_index = 0;
for (let char of text) {
if (alphabet.includes(char.toUpperCase())) {
let char_index = alphabet.indexOf(char.toUpperCase()) + 1;
let key_char = key[key_index % key.length];
let key_index = (key_index + 1) % key.length;
let encrypted_char = alphabet[(char_index + char.charCodeAt(0)) % alphabet.length];
cipher_text += encrypted_char;
} else {
cipher_text += char;
}
}
return cipher_text;
}
// Example usage:
let text = 'Hello, World!';
let key = 'secret_key';
let encrypted_text = vigenere_cipher(text, key);
console.log(encrypted_text);