Files
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

1.9 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
68216ef80f957572e7c340c5 Challenge 12: Message Decoder 29 challenge-12

--description--

Given a secret message string, and an integer representing the number of letters that were used to shift the message to encode it, return the decoded string.

  • A positive number means the message was shifted forward in the alphabet.
  • A negative number means the message was shifted backward in the alphabet.
  • Case matters, decoded characters should retain the case of their encoded counterparts.
  • Non-alphabetical characters should not get decoded.

--hints--

decode("Xlmw mw e wigvix qiwweki.", 4) should return "This is a secret message."

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode("Xlmw mw e wigvix qiwweki.", 4), "This is a secret message.")`)
}})

decode("Byffi Qilfx!", 20) should return "Hello World!"

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode("Byffi Qilfx!", 20), "Hello World!")`)
}})

decode("Zqd xnt njzx?", -1) should return "Are you okay?"

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode("Zqd xnt njzx?", -1), "Are you okay?")`)
}})

decode("oannLxmnLjvy", 9) should return "freeCodeCamp"

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode("oannLxmnLjvy", 9), "freeCodeCamp")`)
}})

--seed--

--seed-contents--

def decode(message, shift):

    return message

--solutions--

def decode(message, shift):
    decoded_message = []
    for char in message:
        if char.isalpha():
            base = ord('a') if char.islower() else ord('A')
            new_char = chr((ord(char) - base - shift) % 26 + base)
            decoded_message.append(new_char)
        else:
            decoded_message.append(char)
    return ''.join(decoded_message)