Stupid Puzzle box

The space was sent a cool puzzle box as part of a secret santa. One of the puzzles involves getting the output of a flashing light into an LDR on the other side of the box. I played with this with another member last week, we decided to try and decode the light output.

I am sure we don't need to do this, but I wanted to try out my idea. He tried to use FinalCut to process a vide of the output, but this didn't work. I suggested we try breaking the video down to frames, running a brightness threshold over them, then generating a plot of the output.

Turn the video into frames:

$ ffmpeg -i VID.mp4  -f image2 frames/image-%07d.png

We can use convert from imagemagick to threshhold an image, here we convert its colour space into hue saturation and brightness and resize the image down to 1x1. Convert will give a text description of what it did so we don't have loads of temporary images.

I hand picked a 'dark' image:

$ convert dark.png -colorspace hsb -resize 1x1 txt:- 
# ImageMagick pixel enumeration: 1,1,65535,hsb                        
0,0: (10086,47272,7376)  #27B81D  hsb(55,72%,11%)

And a 'light' image:

$ convert light.png -colorspace hsb -resize 1x1 txt:-    
# ImageMagick pixel enumeration: 1,1,65535,hsb
0,0: (32525,17838,41551)  #7F45A2  hsb(179,27%,63%)

I ran convert over each file with some awk magic:

for filename in frames/*png; do
    echo $filename
    convert $filename -colorspace hsb -resize 1x1 txt:- | tail -n 1 | awk '{ print $4}' | awk -F "," '{ print $3}' | sed -e "s/%)//" >> outfile
done

I ran the outputfile through matplotlib to generate a nice plot of the light values.

import matplotlib.pyplot as plt

values = []

with open("outfile", "r") as f:
    for line in f.readlines():
        value = int(line)

        if value > 40:
            value = 100
        else:
            value = 10
        values.append(value)

plt.figure(figsize=(30,2))

plt.plot(values)
plt.ylabel('brightness')

plt.savefig("plot.png")

The hardest part of this was getting the video off my phone, the most time consuming was installing matplotlib.

Reading: Normal

Why can't I send UDP packets from a browser?

You can't because it is a terrible idea, and yet this post explains a really reasonable way forward. My first thought was hopefully the same as yours, "That is absolute insanity, won't someone think of the DDOS?". Glenn Fiedler is responsible for the most pervasive game networking tutorial , it is the beej net guide for games.

This isn't a general interface for UDP, that is of course insane. Instead it is networking library specifically for real time games. It uses http authentication to generate a security token then offers a frame locked secure datagram API for moving real time data. The proposed API has hard timeouts, latency and bandwidth expectations, really not useful for anything other than games.

Right now there is a c library available on github. It will be interesting to see a prototype javascript interface.


Reading: Normal

Don't use SHA1


It is Sunday, so that makes seven days of writing .

Have you subscribed to orbital operations yet? You should.

Reading: Normal

curling down bibtex

When I wrote the last post I really wanted to use curl to turn rfc numbers and drafts into bibtex entries. I did have a look, but I had other things to do that seem urgent and I didn't follow it through.

That was lazy of me, the page will generate an error message with a url when given an rfc or draft that doesn't exist. I looked at this url with a valid rfc, but it wasn't clear how to turn the returned info into a bibtex entry.

Stripping that div off the page makes the url visible:

Failed to read RFC or Internt-Draft resource at http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.9999.xml

Using that url format with a valid rfc number (Our beloved RFC768 ) spits out this xml document:

$ curl  http://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.0768.xml
<?xml version='1.0' encoding='UTF-8'?>

<reference  anchor='RFC0768' target='http://www.rfc-editor.org/info/rfc768'>
<front>
<title>User Datagram Protocol</title>
<author initials='J.' surname='Postel' fullname='J. Postel'><organization /></author>
<date year='1980' month='August' />
</front>
<seriesInfo name='STD' value='6'/>
<seriesInfo name='RFC' value='768'/>
<seriesInfo name='DOI' value='10.17487/RFC0768'/>
</reference>

That is how far I got when I gave up earlier. Looking at the page again I thought I might try looking at the network traffic it generates.

That is much more interesting, the page itself is doing a request to https://sysnetgrp.no-ip.org . Lets try a curl there and see what we get:

$ curl "https://sysnetgrp.no-ip.org/rfc/rfcbibtex.php?type=RFC&number=768"    
@techreport{RFC0768,
  author = {J. Postel},
  title = {User Datagram Protocol},
  howpublished = {Internet Requests for Comments},
  type = {STD},
  number = {6},
  year = {1980},
  month = {August},
  issn = {2070-1721},
  publisher = {RFC Editor},
  institution = {RFC Editor},
  url = {http://www.rfc-editor.org/rfc/rfc768.txt},
  note = {\url{http://www.rfc-editor.org/rfc/rfc768.txt}},
}

Much better!

IETF Document to Bibtex

I am writing stuff up right now so I am not really doing anything that interesting. Users of latex for academic work will know the nightmare that is generating bibtex entries. Thankfully for ietf rfc and drafts entries are automatically generate. I found this blog post that includes a tool for looking up an entry and getting its bibtex.


Reading: Normal