Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/68e39ed6106dac2f0a98fd65.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

2.5 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
68e39ed6106dac2f0a98fd65 Challenge 83: Signature Validation 29 challenge-83

--description--

Given a message string, a secret key string, and a signature number, determine if the signature is valid using this encoding method:

  • Letters in the message and secret key have these values:
    • a to z have values 1 to 26 respectively.
    • A to Z have values 27 to 52 respectively.
  • All other characters have no value.
  • Compute the signature by taking the sum of the message plus the sum of the secret key.

For example, given the message "foo" and the secret key "bar", the signature would be 57:

f (6) + o (15) + o (15) = 36
b (2) + a (1) + r (18) = 21
36 + 21 = 57

Check if the computed signature matches the provided signature.

--hints--

verify("foo", "bar", 57) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(verify("foo", "bar", 57), True)`)
}})

verify("foo", "bar", 54) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(verify("foo", "bar", 54), False)`)
}})

verify("freeCodeCamp", "Rocks", 238) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(verify("freeCodeCamp", "Rocks", 238), True)`)
}})

verify("Is this valid?", "No", 210) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(verify("Is this valid?", "No", 210), False)`)
}})

verify("Is this valid?", "Yes", 233) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(verify("Is this valid?", "Yes", 233), True)`)
}})

verify("Check out the freeCodeCamp podcast,", "in the mobile app", 514) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(verify("Check out the freeCodeCamp podcast,", "in the mobile app", 514), True)`)
}})

--seed--

--seed-contents--

def verify(message, key, signature):

    return message

--solutions--

def verify(message, key, signature):
    def charValue(ch) -> int:
        if 'a' <= ch <= 'z':
            return ord(ch) - ord('a') + 1
        elif 'A' <= ch <= 'Z':
            return ord(ch) - ord('A') + 27
        else:
            return 0

    def compute_sum(s):
        return sum(charValue(ch) for ch in s)

    total = compute_sum(message) + compute_sum(key)
    return total == signature