Double Underscore Name Mangling

Hard ⏱ 18 min 32% acceptance ★★★★☆ 4.2
Attributes named __secret (two leading underscores) are rewritten to _ClassName__secret. Build Vault storing __pin from the constructor with a method check(pin) comparing against it. Then write the module-level function crack(vault) that reads the pin anyway via the mangled name — proving mangling is collision-avoidance, not security.

Examples

Example 1
Input
Vault('1234').check('1234')
Output
True
Explanation

Inside the class the name works unmangled.

Example 2
Input
crack(Vault('1234'))
Output
'1234'
Explanation

The mangled attribute is reachable from outside.

Constraints

  • Use exactly two leading underscores.
  • crack must use the mangled form.

Topics

OOPname mangling

Companies

GoogleMetaOracle

Hints

Hint 1

The mangled name is _Vault__pin.

Hint 2

getattr(vault, "_Vault__pin") or direct attribute access.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.