0

I have recently developed a proprietary data storage type - a bunch of black/white squares on a printed piece of paper which I can scan with a scanner. To me, this has two main benefits:

  • If I had important photos on my hard drive and they got lost, I wouldn't be able to retrieve them (most likely). However, on my proprietary format, all data is physical and thus can't be lost (unless your like me and tend to misplace things an awful lot.)
  • The data stored on the paper cannot be "stolen" by hackers etc.

So, I have programmed a simple algorithm which takes a ~2.5KiB file and converts it into this format (each "bit" of information is a 4x4 block of pixels):

from PIL import Image, ImageDraw

im = Image.new("RGB",((160*4)+2, (128*4)+2), "white")
pix = im.load()
dw = ImageDraw.Draw(im)

dw.rectangle([0,0,160*4+1,128*4+1], outline=(0,0,255))

with open("program.exe", mode="rb") as f:
    l = list(f.read())
    # we now have the numerical binary!
    # time to convert each number into a bit!
    binary = ""
    temp = ""
    for a in l:
        temp = format(a, "#010b")[2:]
        binary += temp
    idx = 0
    print(len(binary))

    for y in range(1, im.size[1]-1, 4):
        for x in range(1, im.size[0]-1, 4):
            ax = binary[idx]
            if ax == "1":
                for i in range(0, 4):
                    for j in range(0, 4):
                        pix[x+j, y+i] = (0,0,0)

            idx += 1

im.show()
im.save("code.png")

If you are wondering, program.exe is a binary executable written in x86 assembly which just prints hello, world! to the terminal.

However, I can't quite figure out how to (after scanning) convert the scanned image back into machine code, and write it to an executable. It seems that each time, there is some fuzzy-noise in the background of the image which I can't seem to remove, and there is also the fact that the image is somewhat skewed. I tried a python library called pyzbar (and yes, I do know it is for barcodes and QR-Codes, but I had hope it may be able to recognise at least something, but I was grasping at straws and nothing came out on the output.

Would anyone know how to do this (like image recognition or something to read data)?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • You seem to be confused. Physical items are easily lost, misplaced, damaged, or destroyed, and tend to be cumbersome and costly to store safely, whereas digital data can safely be copied to multiple locations. Use encryption if it needs to be confidential. – tripleee Aug 22 '20 at 18:23
  • Oh no, I know. It's just for my purposes and that as I described, I do often misplace things but under certain conditions, paper can last for as many as 400+ years. It's more of a "is it possible to do this thing" kind of data storage. – sciencepiofficial Aug 22 '20 at 18:27
  • maybe you should use module `cv2` (OpenCV) - you could even find examples which shows how to recognize rectangles or other figures or even chessboard. – furas Aug 22 '20 at 23:12

0 Answers0