mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
2.7 KiB
2.7 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69bc6cb30c1d112a2e110a07 | Challenge 250: Hidden Key | 29 | 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:
- Look at the corresponding letter in the key (repeat the key if the message is longer than the key).
- Convert the key letter to its corresponding number:
"A"= 1,"B"= 2, ...,"Z"= 26. - Shift the encoded letter backward in the alphabet by that number.
- 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".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode("YAVJYNXE"), "CONGRATS")`)
}})
decode("YALLUT PQUMJP") should return "CODING LEGEND".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode("YALLUT PQUMJP"), "CODING LEGEND")`)
}})
decode("UAC DYR EISAKYM") should return "YOU ARE AWESOME".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode("UAC DYR EISAKYM"), "YOU ARE AWESOME")`)
}})
decode("GQMS NBMZU") should return "KEEP GOING".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(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".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode("W IQQURV UG I ZDMDTRV IVW JQDHY TMHSA QB"), "A WINNER IS A DREAMER WHO NEVER GIVES UP")`)
}})
--seed--
--seed-contents--
def decode(message):
return message
--solutions--
def decode(message):
key = "VLHCGMDLNH"
result = []
key_index = 0
for char in message:
if char == ' ':
result.append(char)
else:
shift = ord(key[key_index % len(key)]) - 64
key_index += 1
result.append(chr((ord(char) - 65 - shift) % 26 + 65))
return ''.join(result)