Secret Messages and Background Radiation

Posted by F1ak3r on Feb. 24, 2014, 2:23 p.m.

I've been back at uni for two weeks now, but it feels like it's been an age. Seeing as I'm in Honours1 now, I get a desk and a PC in an air-conditioned room. I also get a whole lot of assignments and a thesis to write, I guess to ensure I'll be making the most of that PC at that desk in that air-conditioned room.

So most days I go in, attend a few lectures in the morning, break for lunch and then spend the afternoon working on assignments until supper. It's like having a full-time job, but to quote one of our lecturers, "if you come in every day at 8 and leave at 5, near the end of the year you'll be coming in every day at 8 and leaving at midnight".

I'll be doing six courses this year, in order:
* Image Processing
* Artificial Intelligence
* Mobile Computing
* Parallel Processing
* Computer Security
* Real Time Multimedia (basically networking)

There's also Project Management, but that's just overhead for doing our projects, stuff like how to reference2, how to use LaTeX (which made most of the previous item pointless) and how to give a presentation (turns out you have to speak to the audience and not read from slides, who knew).

My thesis project is on characterising Internet Background Radiation, which is basically packets sent to addresses that supposed to be receiving them, and can be thought of as the side-effects of DDOS attacks, worms, botnets, and simple hardware misconfigurations. I worked a bit with network telescopes at my internship over December, so I have some idea of what I'm going to be doing and dealing with, but there's obviously a whole lot I still have to learn.

1 – In South Africa, most undergraduate degrees are three years long. Because this is different from the four year degrees in place in other parts of the world, most people end up doing Honours degrees the year after finishing undergrad, so that they can emigrate and still be considered to have a degree.
2 – Which I had drilled into my head by commerce subjects in first year, but apparently my friends doing Maths as their second major never had to bother with citing sources and figuring out the arcane rules of whatever referencing method the department had slapped together and called the "Harvard Referencing Style".


Course-wise, I've started only the first one, Image Processing, and that's been pretty neat. Our lecturer is what you get when you cross a classic farm-grown Afrikaner with a crazy Linux hacker who's always mentioning the mouse driver he wrote in highschool and the proto-VOIP system he and some others made in masters for the sole purpose of being able to talk to the secretary of their building without going down six flights of stairs.

We’ve had three assignments for that so far: (1) write programs to manually perform manipulations like greyscaling, scaling and rotation on images in PPM formats (2) write a program to mark multiple choice answer sheets (the type where you colour in dots to indicate what answer you gave) and (3) write a program to hide messages in images and decode them.

The first assignment I did by manually editing files (PPMs are quite nicely formatted and space-wasting so you can do that fairly reasonably), and for the second and third I’ve been using the OpenCV library, which reads in images in [Y, X, BGR] matrices, because I guess standards are boring. All my code’s in Python, of course, because Python is love.

The marker works about 70% of the time. I’ve just been doing it by checking the average colouring of each circle according to its fixed co-ordinates (which I’ll make dependent on the image size later). Of course it’ll all break if the user scans in a marksheet skew, and I still have to tweak the colours a bit more to catch that other 30%, but it basically works even after I spent most of my time wondering why it wasn’t working when I gave it X,Y co-ordinates like a normal human being.

The hidden messages thing I’ve just started. I’m converting the message into binary, and then using the (x % 2) of each colour channel to hide it (an idea someone much smarter than I came up with). So if I want to hide 0110100001100101011011000110110001101111 and my image starts (215 30 98) (73 50 147) … i.e. 100101, I just minus one from each incorrect value and get (214 29 97) (72 49 146) … which will be evaluated as 0110100001100101011011000110110001101111 when I need to decode. And you can store a lot of text in a reasonably-sized image without significantly changing its size, making it sort of like a strange, inefficient compression method as well. I’ll dump the code here with an image once I get it working properly.

I’m also “tutoringâ€? second year students now, which basically means helping them out at practicals and marking their hand-ins. Never did it in previous years, but postgrads get paid more for tutoring than undergrads, so I figured it was really only worth the effort now – my other part time job, fixing student computers, pays more per hour for fewer average hours per week. Another reason why is that second year was my worst year marks-wise, so I’m kinda using tutoring, with the added pressure of needing to understand stuff well enough to explain it to others, as an opportunity to really learn the coursework properly – the current section, MIPS assembly, was a definite low point of my undergrad and something I hardly understood at the time.

So I’ve been really busy. How are you guys?

EDIT 02/03/2013:


# Hiding Messages in Images
#
# 
# Just do this to encode messages:
#
# python hidemessage.py -e <filewithmessage> <imagetohidein>
#
# 
# ...and do this to decode messages:
#
# python hidemessage.py -d <imagetodecode>
#
# 
# End messages with one ` to tell the decoder when to stop. PNGs recommended.
# 
# Python 2.7.5+, requires OpenCV.
 
import sys, getopt, cv2, base64, binascii
 
"""
Encode message in image
"""
def encode(img, msg):
    binmsg = "".join('{:08b}'.format(ord(c)) for c in msg)
    msgcounter = 0
    for x in range(0, img.shape[1]):
        for y in range(0, img.shape[0]):
            for c in range(0,3):
                iodd = img[y, x, c] % 2
                modd = binmsg[msgcounter]
                if iodd != int(modd):
                    if img[y,x,c] == 255:
                        img[y, x, c] -= 1
                    elif img[y,x,c] == 0:
                        img[y,x,c] += 1
                    else:
                        img[y,x,c] -= 1
                if msgcounter+1 < len(binmsg):
                    msgcounter += 1
                else:
                    return img
    return img
 
"""
Decode message from image
"""
def decode(img):
    characters = []
    for x in range(0, img.shape[1]):
        for y in range(0, img.shape[0]):
            for c in range(0,3):
                characters.append(str(img[y, x, c] % 2))
 
    binmsg = "".join(characters)
    msglist = []
    for c in range(0, len(binmsg), 8):
        char = chr(int(binmsg[c:c+8], 2))
        if char != "`":
            msglist.append(char)
        else:
            break
 
    return "".join(msglist)
 
def usage():
    print("""Usage: python message.py [ options... ] [image]
    -e/--encode [file] -- Encode message in given file
    -d/--decode -- Decode message""")
 
def main(argv):
    try:
        opts, args = getopt.getopt(argv, "he:d", ["help", "encode=", "decode"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
 
    img = cv2.imread(args[0])
 
    for opt, arg in opts:
        if opt in ("-h","--help"):
            usage()
            sys.exit()
        elif opt in ("-e", "--encode"):
            with open(arg, 'r') as thefile:
                message = thefile.read()
            codedimage = encode(img, message)
            cv2.imwrite("coded.png", codedimage)
        elif opt in ("-d", "--decode"):
            message = decode(img)
            print(message)
 
if __name__ == '__main__':
    main(sys.argv[1:])

Comments

Aistarin 5 years, 7 months ago

Quote:
I'll be doing six courses, in order:
* Image Processing
* Artificial Intelligence
* Mobile Computing
* Parallel Processing
* Computer Security
* Real Time Multimedia (basically networking)
Even for a semester system that is an insane courseload.

And Josea called ME crazy…

NeutralReiddHotel 5 years, 7 months ago

it amazes me how many courses you're doing f1ak3r… i'm taking 5, and a couple of them are pretty easy so i should get by fine, but I still struggle with the hard ones (OCHEM, ochem lab), I wonder how it is that you can take 6 pretty challenging courses and still retain all that information for exams … it's impressive, really

Acid 5 years, 7 months ago

That is definitely too much at once for me.

F1ak3r 5 years, 7 months ago

We, err, have to do at least six, so this was as low as I could go :/ . I've got them spaced out so that I have three this semester and three next, with as little overlap as possible (of course they just had to put Security at the same time as Parallel…) but with the thesis as well it's certainly going to be a busy year.

Acid 5 years, 7 months ago

I thought you were taking them all at once! 3 is MUCH more feasible. I couldn't function in 6 programming classes at once!

F1ak3r 5 years, 7 months ago

Hells no. I would literally die.

Acid 5 years, 7 months ago

F1ak3r, you just literally fucking ruined my day.

Aistarin 5 years, 7 months ago

Ok good, what a relief, I also thought you were doing that in one semester.

My biggest CS courseload for a quarter (3 months) was computer graphics, operating systems, algorithm design and analysis, and software development with Android. I had a similar courseload last fall, but I actually had a lot of fun making shit with 7400 series ICs and it turned out to be my best quarter at this school so far.

aeron 5 years, 7 months ago

Ooh the hidden message thing reminds me of steganography. Certainly an interesting application of image data ;)

Also, I was thinking of doing something similar to your marker assignment to extract data from these images. I was excited when I found this but quickly disappointed to find they were only available as images (and he left no contact details on his page for me to reach him by). So I guess I'll be joining you in your image processing ventures pretty soon :P

Edit:

Edit2:

F1ak3r 5 years, 7 months ago

It's funny, our lecturer went over steganography the day after you posted that, aeron. We went over some methods of hiding images in other images, though it's not as hard to detect when you do that as it is with text.

Anyway, I got my code working, and here's a demonstration I tweeted earlier: the code, and the image.

Copyright 2019 64Digits.