from PIL import Image from hacker.decoder import decode, toint16 from hacker.settings import inputfile filename = inputfile('crypto', 'didactic_rgb', 'didactrgb.png') rgb = Image.open(filename).load()[0, 0] result = int(decode(rgb, toint16), 16) print(result)
from hacker.settings import inputfile filename = inputfile('coding', 'pi_hates_nines', 'pi1000000.txt') with open(filename, 'r') as file: pi = file.read().strip() result = sorted(list(pi.split('9')), key=len)[-1] print(result)
from PIL import Image from hacker.settings import inputfile, outputfile from util.primes import is_prime filename = inputfile('crypto', 'white_noise', 'whitenoise.png') filename_out1 = outputfile('crypto', 'white_noise', 'whitenoise_out1.png') filename_out_prime = outputfile('crypto', 'white_noise', 'whitenoise_out_prime.png') im = Image.open(filename) # Set the first index in the palette (this outputs an image with a hint) palette = bytearray(256*3) palette[:3] = [255, 255, 255] im.putpalette(palette) im.save(filename_out1, 'PNG') # Set the prime numbers palette = bytearray(256*3) for i in range(256): if is_prime(i + 1): palette[i*3:i*3+3] = [255, 255, 255] im.putpalette(palette) im.save(filename_out_prime, 'PNG') print('The solution is worldofprimenoise')
from hacker.bytestreams import bytes_from_binary from hacker.decoder import decode from hacker.settings import inputfile from hacker.text import remove_punctuation filename = inputfile('crypto', 'didactic_text_4', 'text.txt') with open(filename, 'r') as file: value = file.read() value = remove_punctuation(value).lower() translation = { 'he': 0, 'him': 0, 'his': 0, 'himself': 0, 'she': 1, 'her': 1, 'hers': 1, 'herself': 1, } binary = decode(filter(lambda w: w in translation, value.split()), translation, str) result = decode(bytes_from_binary(binary), chr) print(result)
from collections import Counter from hacker.settings import inputfile # Source: https://www.rfc-editor.org/rfc/rfc3280.txt filename = inputfile('coding', '3280', 'rfc3280.txt') with open(filename, 'r') as file: value = file.read() print(Counter([x for x in value.split() if len(x) == 9]).most_common()[0][0])
from hacker.bytestreams import ungroup, bytes_from_binary from hacker.decoder import transform, decode from hacker.images import pixels from hacker.settings import inputfile, outputfile filename = inputfile('crypto', 'lucy_in_the_sky_with_briolettes', 'briolette.png') outputfilename = outputfile('crypto', 'lucy_in_the_sky_with_briolettes', 'briolette.txt') temp = decode(ungroup(transform(pixels(filename), lambda p: p[:3])), lambda v: v % 2, str) print(temp) print(len(temp) % 8) print(min(bytes_from_binary(temp, 5))) print(max(bytes_from_binary(temp, 5))) with open(outputfilename, 'wb') as output: output.write(bytes(bytes_from_binary(temp))) result = decode(bytes_from_binary(temp, 10), lambda s: s % 128, chr) print('START') i = 0 for c in result: if 32 <= ord(c) <= 126: print(c, end='') else: print(f'<{ord(c):02x}>', end='') i += 1 if i % 24 == 0:
from hacker.decoder import decode from hacker.images import pixels from hacker.settings import inputfile filename = inputfile('crypto', 'didactic_green', 'greenline.png') result = decode(pixels(filename), lambda x: x[1], chr) print(result)
from PIL import Image from hacker.bytestreams import ungroup from hacker.decoder import transform from hacker.images import pixels from hacker.settings import inputfile, outputfile filename = inputfile('crypto', 'listen_to_me', 'listen.png') outputfilename = outputfile('crypto', 'listen_to_me', 'listen.raw') with open(outputfilename, 'wb') as output_file: im = Image.open(filename) output_file.write( bytes(ungroup(transform(pixels(filename), lambda p: p[:3])))) # The result are raw sound values. Playing the resulting sound file, it says: print('1234')
from PIL import Image from hacker.settings import inputfile, outputfile filename = inputfile('crypto', 'redeye', 'redeye.jpg') filename_out = outputfile('crypto', 'redeye', 'redeye2.jpg') im = Image.open(filename) r, g, b = im.split() r.save( filename_out, 'JPEG' ) # In the bottom right corner of the resulting image print('HAL9000')
from hacker.bytestreams import ungroup, bytes_from_binary from hacker.decoder import transform, decode from hacker.images import pixels from hacker.settings import inputfile, outputfile from PIL import Image filename = inputfile('crypto', 'filtration_residue', 'residue.png') outputfilename = outputfile('crypto', 'filtration_residue', 'residue2.png') im = Image.open(filename) im = im.convert('RGB') pix = im.load() mod_val = 16 div_val = mod_val - 1 width, height = im.size for i in range(height): for j in range(width): pix[j, i] = ((pix[j, i][0] % mod_val) * (255 // div_val), (pix[j, i][1] % mod_val) * (255 // div_val), (pix[j, i][2] % mod_val) * (255 // div_val)) im.save(outputfilename, 'PNG') # for p in ungroup(pixels(filename)): # print(p%2, end='') # IDEA Look at text chunks # Source: https://github.com/ctfs/write-ups-2015/tree/master/confidence-ctf-teaser-2015/stegano/a-png-tale-200 # IDEA find out why it fails and what that means
from PIL import Image from hacker.settings import inputfile, outputfile filename = inputfile('crypto', 'forest_for_the_trees', 'green.jpg') outputfilename = outputfile('crypto', 'forest_for_the_trees', 'green2.jpg') im = Image.open(filename) im = im.convert('RGB') pix = im.load() test = {} width, height = im.size for i in range(height): for j in range(width): test[pix[j, i]] = 0 pix[j, i] = (0, 255 if pix[j, i][2] else 0, 0) im.save(outputfilename, 'JPEG') print('colorblind')
from hacker.decoder import decode from hacker.settings import inputfile filename = inputfile('crypto', 'didactic_vampire_text', 'text.txt') with open(filename, 'r') as f: value = f.read() result = decode(filter(str.isupper, value)) print(result)
from hacker.decoder import decode, toint16 from hacker.images import pixels from hacker.settings import inputfile filename = inputfile('crypto', 'didactic_red', 'redline.png') result = decode(pixels(filename), lambda x: x[0], toint16) print(result)
import wave from hacker.settings import inputfile, outputfile # satan.mp3 was converted to satan.wav using: # http://audio.online-convert.com/convert-to-wav with wave.open(inputfile('crypto', 'voices_in_my_head', 'satan.wav'), 'r') as w, \ wave.open(outputfile('crypto', 'voices_in_my_head', 'satan_rev.wav'), 'w') as w_reversed: w_reversed.setparams(w.getparams()) length = w.getnframes() frames = [w.readframes(1) for _ in range(length)] for frame in frames[::-1]: w_reversed.writeframes(frame) # The file then says print('The answer is insecticide')
from typing import Iterable from hacker.settings import inputfile from util.primes import is_probable_prime filename = inputfile('coding', 'primal_pi', 'pi1000000.txt') with open(filename, 'r') as file: pi = file.read().strip() length = 2048 piece_of_pi = pi[2:2 + length] def overlapping_substrings(string: str, size: int) -> Iterable[str]: """ Yields all substrings of a given length from a string """ for i in range(len(string) + 1 - size): yield string[i:i + size] prime = None while not prime: print(f'checking length {length}') for s in overlapping_substrings(piece_of_pi, length): if is_probable_prime(int(s)): prime = s break length -= 1 print(prime)
from hacker.settings import inputfile filename = inputfile('crypto', 'updike_cipher', 'updike.html') result = '' with open(filename, 'r') as file: previous_line = '' for line in file.readlines(): if previous_line.startswith('<p>'): result += line[0] if line[0].isalpha() else '' previous_line = line print(result)
from PIL import Image from hacker.bytestreams import ungroup from hacker.decoder import toint16 from hacker.images import pixels from hacker.settings import inputfile, outputfile filename = inputfile('crypto', 'fuzzy_dust', 'fuzz.bmp') i = 0 for p in ungroup(pixels(filename)): print(toint16(p)) if i > 100: break i += 1 filename_out_r = outputfile('crypto', 'fuzzy_dust', 'fuzz_r.jpg') filename_out_g = outputfile('crypto', 'fuzzy_dust', 'fuzz_g.jpg') filename_out_b = outputfile('crypto', 'fuzzy_dust', 'fuzz_b.jpg') im = Image.open(filename) r, g, b = im.split() r.save(filename_out_r, 'JPEG') g.save(filename_out_g, 'JPEG') b.save(filename_out_b, 'JPEG')
from collections import Counter from hacker.bytestreams import bytes_from_binary, skip from hacker.decoder import decode from hacker.images import pixels, size from hacker.settings import inputfile from hacker.util import x_max, x_min filename = inputfile('crypto', 'blizzard', 'blizzard.png') width, height = size(filename) print(width, height) # 5 * 83, 7 * 47 temp = decode(pixels(filename), lambda p: '1' if p[0] else '0') print(temp) print(Counter(temp)) #result = decode(skip(bytes_from_binary(temp, 7), 47), chr) #print(result) from PIL import Image from hacker.decoder import decode, toint2 im = Image.open(filename) pix = im.load() width, height = im.size # IDEA try other "shapes", skipping X bits, etc.
# extract the gz file, then # Write the data in HEX for get calls # tcpdump -A -r smellassweet > smellassweetgets from hacker.settings import inputfile for line in open(inputfile('web', 'smell_as_sweet', 'smellassweetgets')): if line.startswith('\t0x'): t = line[10:].strip().replace(' ', '') for i in range(0, len(t), 2): print(chr(int(t[i:i + 2], 16)), end='') print()
from hacker.images import pixels from hacker.settings import inputfile filename = inputfile('crypto', 'butterfly_effect', 'butterfly.png') for p in pixels(filename): print(p) # IDEA This reminds me of mandelbrot stuff? Not sure there's something to be done with that
from hacker.decoder import decode from hacker.settings import inputfile value = 'Thy raiment waxed not old upon thee, neither did thy foot swell, these forty years. And it shall be, when the officers have made an end of speaking unto the people that they shall make captains of the armies to lead the people. And it shall be, if thou have no delight in her, then thou shalt let her go whither she will; but thou shalt not sell her at all for money, thou shalt not make merchandise of her, because thou hast humbled her. Look down from thy holy habitation, from heaven, and bless thy people Israel, and the land which thou hast given us, as thou swarest unto our fathers, a land that floweth with milk and honey. Now therefore write ye this song for you, and teach it the children of Israel: put it in their mouths, that this song may be a witness for me against the children of Israel. But Jeshurun waxed fat, and kicked: thou art waxen fat, thou art grown thick, thou art covered with fatness; then he forsook God which made him, and lightly esteemed the Rock of his salvation. And I commanded you at that time all the things which ye should do. When a man hath taken a new wife, he shall not go out to war, neither shall he be charged with any business: but he shall be free at home one year, and shall cheer up his wife which he hath taken. When a man hath taken a wife, and married her, and it come to pass that she find no favour in his eyes, because he hath found some uncleanness in her: then let him write her a bill of divorcement, and give it in her hand, and send her out of his house. They shall call the people unto the mountain; there they shall offer sacrifices of righteousness: for they shall suck of the abundance of the seas, and of treasures hid in the sand. Cursed shalt thou be when thou comest in, and cursed shalt thou be when thou goest out.' # noqa filename = inputfile('crypto', 'didactic_text_2', 'bible.txt') def find_bible_verse(verse): """ Find the specific bible verse in a file containing the King James edition of the bible (Source: gutenberg.org) """ with open(filename, 'r') as file: for line in file.readlines(): if verse[: 50] in line: # The text file has extra newlines, so only check the start for matching return line.split()[0] def index_to_letter(index): """ Convert a 1-index to a letter in the alphabet: 1 -> a,... """ return chr(ord('a') + index - 1) result = decode(value.split('. '), find_bible_verse, lambda s: int(s.split(':')[1]), index_to_letter) print(result)
from PIL import Image from hacker.settings import inputfile, outputfile filename = inputfile('crypto', 'blue_skies_green_grass', 'blueskies.png') outputfilename = outputfile('crypto', 'blue_skies_green_grass', 'blueskies2.png') im = Image.open(filename) im = im.convert('RGB') pix = im.load() width, height = im.size for i in range(height): for j in range(width): pix[j,i] = (255 if pix[j,i][0] else 0, 0, 0) im.save(outputfilename, 'PNG')
from hacker.settings import inputfile filename = inputfile('crypto', 'steganographic', 'boxes.gif') with open(filename, 'rb') as f: value = f.read() result = value[-14:-2] print(result)
from re import compile from hacker.settings import inputfile filename = inputfile('web', 'lorem_ipsum', 'lorem.txt') with open(filename, 'r') as file: value = file.read().lower() words = compile('\w+').findall(value) words.sort() for i in range(1, len(words) - 1): if words[i - 1] != words[i] and words[i] != words[i + 1]: print(words[i]) break
from hacker.settings import inputfile inputfile('coding', 'privy', 'Privy.bin')
from hacker.settings import inputfile inputfile('coding', 'execution_style', 'Doll2.png')