print('Next nothings:') delim = 'Next nothing is ' linked_list = dict() for txtfile in archive.namelist(): key = txtfile[0:-4] contents = archive.read(txtfile).decode('ascii') if delim in contents: next_key = contents.split(delim)[1] else: next_key = None linked_list[key] = [next_key, contents] return linked_list if __name__ == '__main__': pcutils.try_page('def/', 'channel', caption='Challenge page') print() # there is a download for channel.zip # manually put in the project directory archive = get_zip_archive() print() linked_list = create_linked_list() print(f'Linked list:') key = '90052' while key is not None: next_key, message = linked_list[key]
if ch == 'y': return 'a' if ch == 'z': return 'b' return chr(ord(ch) + 2) def shift_all(sentences): return [ ''.join(shift2(ch) if 'a' <= ch <= 'z' else ch for ch in sentence) for sentence in sentences ] if __name__ == '__main__': pcutils.try_page('def/', 'map', caption='Challenge page') print() encoded = pcutils.get_string_from_page('def/', 'map', start='<font color="#f000f0">', end='</tr></td>') pcutils.print_lines(encoded.split('. '), 'Message to decode') pcutils.print_lines(''.join(shift_all(encoded)).split('. '), 'Decoded message') page = ''.join(shift2(ch) for ch in 'map') print(f'map shifted: {page}') pcutils.try_page('def/', page, '.html', caption='Next challenge page')
def get_answer(): n = '1' answers = [n] for i in range(1, 31): answers.append(look_and_say(answers[i - 1])) print(f'Look and say lengths:') for i, n in enumerate(answers): print(f' n = {i} -- length = {len(n)}') print() return str(len(answers[30])) if __name__ == '__main__': pcutils.try_page('return/', 'bull', un=UN, pw=PW, caption='Next challenge page') print() page = 'sequence' pcutils.try_page('return/', page, ending='.txt', un=UN, pw=PW, caption='Clue') message = pcutils.get_string_from_page( 'return/', page, ending='.txt', un=UN, pw=PW) print(f'Message: {message}') pcutils.try_page('return/', get_answer(), un=UN, pw=PW, caption='Next challenge page')
print(f'image shape: height={height}, width={width}, channels={channels}') print() print(f'Gray bar pixels (line 43):') result = '' for x in range(1, 604, 7): (b, g, r) = page_image[43, x] print(f'(b, g, r) pixel at x={x}: ({b}, {g}, {r})') result += chr(b) print() return result def get_message(s): lines = s.split('. ') pcutils.print_lines(lines, 'Message from the bar') print() message = list(map(int, lines[1].split('[')[1][0:-1].split(', '))) return ''.join(map(chr, message)) if __name__ == '__main__': pcutils.try_page('def/', 'oxygen', caption='Challenge page') answer = get_message(get_gray_bar('oxygen')) pcutils.try_page('def/', answer, caption='Next challenge page') os.remove('oxygen.png')
'raw_unicode_escape') pw_bytes = un_pw[1][5:-1].decode('unicode_escape').encode( 'raw_unicode_escape') un = bz2.decompress(un_bytes).decode('ascii') pw = bz2.decompress(pw_bytes).decode('ascii') return un, pw if __name__ == '__main__': # pcutils.try_page('def/', 'integrity', # caption='Challenge page') # from url text next_page = 'good' print(f'Next challenge page is ...return/{next_page}.html.') print(f' It needs a username / password.') print() un, pw = get_auth() print(f'Username: {un}') print(f'Password: {pw}') print() pcutils.try_page('return/', next_page, un=un, pw=pw, caption='Next challenge page')
import os def create_pickle_info(): pickle_data = pcutils.get_bytes_from_page('def/', 'banner', '.p') outfile = open('pickle.dat', 'wb') outfile.write(pickle_data) outfile.close() infile = open('pickle.dat', 'rb') pickle_table = pickle.load(infile) infile.close() os.remove('pickle.dat') return pickle_table if __name__ == '__main__': pcutils.try_page('def/', 'peak', caption='Challenge page') print() pickle_table = create_pickle_info() pcutils.print_lines(pickle_table, 'Pickle table') print() print(f'Printing banner...') for line in pickle_table: print(''.join(ch * w for ch, w in line)) pcutils.try_page('def/', 'channel', caption='Next challenge page')
10 + max([y for x, y in dots1] + [y for x, y in dots2]), 10 + max([x for x, y in dots1] + [x for x, y in dots2])) for i in range(1, len(dots1)): pt1, pt2 = dots1[i - 1], dots1[i] cv2.line(canvas, pt1, pt2, pcutils.BLACK) for i in range(1, len(dots2)): pt1, pt2 = dots2[i - 1], dots2[i] cv2.line(canvas, pt1, pt2, pcutils.RED) cv2.imshow('Looks like a cow: ', canvas) cv2.waitKey(0) if __name__ == '__main__': pcutils.try_page('return/', 'good', un=UN, pw=PW, caption='Challenge page') print() connect_the_dots(get_dots(1, 'first:', 'second:'), get_dots(2, 'second:', '-->')) print() pcutils.try_page('return/', 'cow', un=UN, pw=PW, caption='Cow page') message = pcutils.get_string_from_page('return/', 'cow', un=UN, pw=PW) print(f'Message: {message}') pcutils.try_page('return/', 'bull', un=UN, pw=PW, caption='Next challenge page')
''' the python challenge 3 ''' import pcutils import re if __name__ == '__main__': pcutils.try_page('def/', 'equality', caption='Challenge page') print() mess_below = pcutils.get_string_from_page('def/', 'equality', start='<!--', end='-->') pcutils.print_lines( mess_below.split(pcutils.NEWLINE)[0:10], 'Mess below from web page') print('...') print() pattern = '[a-z]{1}[A-Z]{3}[a-z]{1}[A-Z]{3}[a-z]{1}' matches = re.findall(pattern, mess_below) pcutils.print_lines(matches, 'Matches') print() page = ''.join(s[4] for s in matches) pcutils.try_page('def/', page, caption='Trying page in url...') message = pcutils.get_string_from_page( 'def/',
''' the python challenge 0 ''' import pcutils if __name__ == '__main__': pcutils.try_page('def/', '0', '.html', caption='Warm up page') print() page = str(pow(2, 38)) pcutils.try_page('def/', page, '.html', caption='New Challenge page')
''' the python challenge 2 ''' import pcutils import collections if __name__ == '__main__': pcutils.try_page('def/', 'ocr', caption='Challenge page') print() s = pcutils.get_string_from_page( 'def/', 'ocr', start='<!--', end='-->', ) mess_below = s[s.index('%'):] pcutils.print_lines( mess_below.split(pcutils.NEWLINE)[0:10], 'Mess below from web page') print('...') print() frequencies = collections.defaultdict(lambda: 0) for ch in mess_below: if ch.isalnum(): frequencies[ch] += 1 pcutils.print_lines(frequencies.items(), 'Frequencies of characters in mess')