Skip to content

Instantly share code, notes, and snippets.

@pawlos
Created December 13, 2019 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawlos/a4893719aa2b36d497ab820b52204d2d to your computer and use it in GitHub Desktop.
Save pawlos/a4893719aa2b36d497ab820b52204d2d to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import sys
from PIL import Image
from nums2 import _f, _g
import struct
im = Image.open(sys.argv[1])
rgb_im = im.convert('RGB')
widht, height = im.size#(1664,1248)
#data = open(sys.argv[1],'rb').read()[0x36:]
res = []
print (widht, height)
for i in range(widht):
for j in range(height):
r, g, b = rgb_im.getpixel((i,j))
bits_r = r & 7 #3 bits
bits_g = g & 7 #3 bits
bits_b = b & 3 #2 bits
v = (bits_b << 6) + (bits_g << 3) + bits_r
res.append(v)
with open('result.dat','wb') as f:
f.write(bytearray(res))
rol = lambda val, r_bits, max_bits: \
(val << r_bits%max_bits) & (2**max_bits-1) | \
((val & (2**max_bits-1)) >> (max_bits-(r_bits%max_bits)))
# Rotate right: 0b1001 --> 0b1100
ror = lambda val, r_bits, max_bits: \
((val & (2**max_bits-1)) >> r_bits%max_bits) | \
(val << (max_bits-(r_bits%max_bits)) & (2**max_bits-1))
max_bits = 8 # For fun, try 2, 17 or other arbitrary (positive!) values
txt = []
num2 = 0
num = 0
for i in range(len(res)):
if i % 100000 == 0:
print(i)
k2, num2 = _g(num, num2)
num += 1
k1, num2 = _g(num, num2)
num += 1
txt.append((ror(rol(res[i], 3, 8) ^ k1, 7, 8) ^ k2))
with open('results.decoded', 'wb') as f:
f.write(bytearray(txt))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment