Space Python Loading Python…

Redact the access code

Write the codeMedium 2 stages

Every login at the ground station goes into the security log, and the first version of the logger wrote the full access code into it. Anyone who could read the log could log in.

Mask the code so only its last four characters show, the way bank cards are printed on receipts, then do it inside a real log line.

Replace every character of the access code except the last four with *, then print it:

Access code: **********77AB

You need as many stars as there are characters before the last four: len(access_code) - 4. "*" * 3 is "***", and access_code[-4:] is the last four characters.

Mask the code
Works for any code

Finish stage 1 to unlock this stage.

In the real log, the code sits inside a line, after code= and up to the next space. Find it, mask it the same way, and print the line with the masked code in its place:

AUTH ok station=Esrange code=**********77AB operator=2

line.find(" ", start) searches for a space starting at index start, so it finds the space after the code, not the first one in the line. Then line.replace(code, masked) builds the new line.

Mask the code in the line
Works for any line
You're not logged in, so your progress is kept in this browser only. Log in to save it, and to use hints and solutions.

Hints

String Indexing and Slicing

string-indexing-slicing.py
# String indexing - every character has a position, counting from 0
mission = "ARTEMIS"
#          0123456

# Grabbing individual characters
print("First letter:", mission[0])    # A
print("Last letter:", mission[-1])     # S

# Slicing [start:stop] - stop is NOT included
print("First three:", mission[0:3])    # ART
print("From index 4 on:", mission[4:])  # MIS
print("Last three:", mission[-3:])      # MIS

# Step slicing [start:stop:step]
launch_code = "A1B2C3D4"
print("Every 2nd:", launch_code[::2])   # ABCD
print("The digits:", launch_code[1::2]) # 1234

# Reversing with a negative step
print("Reversed:", mission[::-1])       # SIMETRA
Open the full example
script.py
PythonLn 1, Col 1Spaces: 4
Loading the Python environment…

Separate arguments with commas. They're passed on every Run as sys.argv[1:].