# conlexiaDemoPython.py — Cross Training: String Manipulation Demo
# Paste into OnlineGDB (https://www.onlinegdb.com/online_python_compiler) and run.
#
# Concept: iterate a string character by character, test each one,
# and accumulate a new string conditionally.
#
# String manipulation vocabulary this demo covers:
#   for symbol in message  — direct iteration; no index, no len(), no i
#   str.lower()            — returns a new string; the original is unchanged
#   lower in targets       — 'in' operator; reads like English
#   str.replace(a, b)      — replaces all occurrences (each letter appears once)
#   random.choice(seq)     — picks a random element from any sequence; no index math
#   str.isupper()          — case test as a method on the string itself
#   str.upper()            — case conversion as a method on the string itself
# ─────────────────────────────────────────────────────────────────────

import random

def scramble_target_letters(message, targets):
    result = ""

    for symbol in message:            # direct string iteration — no index
        lower = symbol.lower()

        if lower in targets:          # 'in' reads like plain English
            # Remove this letter so we always swap, never keep
            pool = targets.replace(lower, "")
            pick = random.choice(pool) # no index math — Python has the tool
            # Preserve original case
            result += pick.upper() if symbol.isupper() else pick
        else:
            result += symbol

    return result

def main():
    targets = "bdpq"
    sample  = ("Peter Piper picked a peck of pickled peppers "
               "quite quickly didn't he, and better than his "
               "buddy Bobby Budden!")

    encrypted = scramble_target_letters(sample, targets)
    print("Original : " + sample)
    print("Encrypted: " + encrypted)

if __name__ == "__main__":
    main()
