Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69bc6cb30c1d112a2e110a07.md
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

88 lines
2.4 KiB
Markdown

---
id: 69bc6cb30c1d112a2e110a07
title: "Challenge 250: Hidden Key"
challengeType: 28
dashedName: challenge-250
---
# --description--
Welcome to the 250th daily challenge!
Given an encoded string, decode it using an encryption key and return it.
To find the key:
- Look at all daily challenges up to today whose challenge number is a multiple of 25 (including this one).
- Take the first letter from each of those challenge titles and combine them into a string. If the title starts with a non-letter, find its first letter.
To decode the message, go over each letter in the encoded message and:
1. Look at the corresponding letter in the key (repeat the key if the message is longer than the key).
2. Convert the key letter to its corresponding number: `"A"` = 1, `"B"` = 2, ..., `"Z"` = 26.
3. Shift the encoded letter backward in the alphabet by that number.
4. If the shift goes before `"A"`, wrap around to `"Z"`.
For example, if the encoded message starts with `"Y"` and the first key letter is `"V"` (22), shift `"Y"` back 22 places to get `"C"`. Repeat this process for each letter to decode the full message.
- Only letters are shifted, spaces are returned as-is.
- All given and returned letters are uppercase.
# --hints--
`decode("YAVJYNXE")` should return `"CONGRATS"`.
```js
assert.equal(decode("YAVJYNXE"), "CONGRATS");
```
`decode("YALLUT PQUMJP")` should return `"CODING LEGEND"`.
```js
assert.equal(decode("YALLUT PQUMJP"), "CODING LEGEND");
```
`decode("UAC DYR EISAKYM")` should return `"YOU ARE AWESOME"`.
```js
assert.equal(decode("UAC DYR EISAKYM"), "YOU ARE AWESOME");
```
`decode("GQMS NBMZU")` should return `"KEEP GOING"`.
```js
assert.equal(decode("GQMS NBMZU"), "KEEP GOING");
```
`decode("W IQQURV UG I ZDMDTRV IVW JQDHY TMHSA QB")` should return `"A WINNER IS A DREAMER WHO NEVER GIVES UP"`.
```js
assert.equal(decode("W IQQURV UG I ZDMDTRV IVW JQDHY TMHSA QB"), "A WINNER IS A DREAMER WHO NEVER GIVES UP");
```
# --seed--
## --seed-contents--
```js
function decode(message) {
return message;
}
```
# --solutions--
```js
function decode(message) {
const key = "VLHCGMDLNH";
let keyIndex = 0;
return message.split('').map(char => {
if (char === ' ') return char;
const shift = key[keyIndex % key.length].charCodeAt(0) - 64;
keyIndex++;
return String.fromCharCode(((char.charCodeAt(0) - 65 - shift + 26) % 26) + 65);
}).join('');
}
```