Programming mission 11

Reverse Ascii Shift

Published on October 2, 2015

Reverse Ascii Shift

The task is to decode a generated ascii string. Furthermore, the time limit is only 5 seconds !

generated string

An example of the generated string

My approach

The time limit of 5 seconds (!) force us to solve this mission completely by scripting. We thus use the selenium webdriver package for python to: 1. Open a browser, 2. Login, 3. Grab the generated string, 4. Solve it and 5. Submit the answer.

1. Open a browser

# URL to the 11th prog mission
url_data = 'https://www.hackthissite.org/missions/prog/11/'

# Open in firefox
driver = webdriver.Firefox()

2. Log in

# Login
log_pass_list = [('your_username','your_password')]

# Load the page
driver.get(url_data)

# Username
inputElement = driver.find_element_by_name('username')
inputElement.send_keys(log_pass_list[0][0])

# Password
inputElement = driver.find_element_by_name('password')
inputElement.send_keys(log_pass_list[0][1])

# Enter
inputElement.send_keys(Keys.ENTER)
time.sleep(0.2)

3. Grab the generated string (from the source code)

# Search for the generated string
search_word = 'Generated String'
start_loc = source.find(search_word)+len(search_word)+2

# Search for the shift statement
search_word = 'Shift'
start_loc = source.find(search_word)+len(search_word)+2
num_shift = int(source[start_loc:start_loc+100].split('<br>')[0])

# Final array to decode
gen_str = clean-num_shift

4. Solve it

# Decoding
asci_str = []
for i in xrange(len(gen_str)):
    asci_str.append(chr(gen_str[i]))

After cleaning the answer to submit we finally arrive at the last step

5. Submit the answer

# Submit solution
inputElement = driver.find_element_by_name('solution')
inputElement.send_keys(to_submit)

# Enter
inputElement.send_keys(Keys.ENTER)
time.sleep(0.2)

And that's it! All done in less than 5 seconds! 

The full code for this mission can be found at Github.