About a week back, the wife and I were watching some television and joked about how
awesome it would be to paint the very first level of Mario in our game room.
Fast forward to today and the joke has taken form, enjoy some of the step
by step pictures I took over the weekend.
First steps were to repaint our game room with a sky blue:
I then installed some chair rail to divide the room, this will keep desk and televisions from covering up the art work:
Next up we painted the chair rail white, and the wife begun painting the Mario scene:
Pipes and shrubs were added, and details painted on top:
The last piece the wife got to this weekend was the start of the stairs:
Just got our copy of Pandemic in the mail, couldn’t pass up on this great deal.
The wife has been really excited about this one, opened up the box and poured a beer.
We just glanced over the rule book until the wife’s finals are over, but excited to see if we can save humanity, or die horribly!
What I’m wanting to do here is demonstrate one way to generate random numbers using a seed. The requirement here is we need to test a number at any given time, this will be useful if we intend to use the process as a token of sort, think RSA SecureID.
Anyways I wanted to make a implementation that used Python and didn’t cost me hundreds
The first thing I needed was a changing number, but one that only changed every 60 seconds.
I decided to use a timestamp here of Year, Month, Day, Hour, Minute in UTC format.
To do this I used the Python time function’s strftime method:
In : import time In : timestamp = time.strftime('%Y%m%d%H%M', time.gmtime()) In : timestamp Out: '201312101409'
Creating a random number using this format is useless since anyone who knows the time
can recreate the output token. To resolve this I’m going to use a salt mixed in with this time string.
A 4 digit key can be used as our salt just fine:
In : key = '1234'
Now we can combine the two in order to make our seed:
In : myseed = key + timestamp In : myseed Out: '1234201312101409'
Excellent we have a salted number we can use as a seed, lets go ahead and use the Python
random library to generate some random ranges using this seed:
In : r = random.Random(myseed) In : r.randrange(000000, 999999) Out: 807766
The beauty about Python’s Random class is it takes a seed for generating random number,
this way we can always guess randomness of the numbers. I also used a output number of
000000 through 999999 (that is a 6 digit random number starting with all 0s and ending
with all 9s).
Below is a few functions thrown together:
import time import random def get_timestamp(): return time.strftime('%Y%m%d%H%M', time.gmtime()) def get_token(key): r = random.Random('%s%s' % (key, get_timestamp())) return r.randrange(000000, 999999) def check_token(key, token): cur = get_token(key) if token == cur: return True return False
Using these functions lets create a token and track at what time it was created.
In : !date Tue Dec 10 08:37:19 CST 2013 In : token = get_token(1234) In : token Out: 771259
Lets check if this token is valid right after creating it:
In : !date Tue Dec 10 08:37:23 CST 2013 In : check_token(1234, token) Out: True
And finally lets wait about a minute and check again:
In : !date Tue Dec 10 08:38:11 CST 2013 In : check_token(1234, token) Out: False
And there you have it, a working proof of concept.
I would like to mention this is purely concept code, it is not very secure. I am also not sure
if the python random library is portable from Python version to version, or even instance to instance.
It has been getting unnaturally cold in Austin Texas this December,
just have a look at our weekend forecast.
If that forecast doesn’t get my point across, this image should:
Anyways, back on topic. With the freezing weather the wife decided it was time
for home made Pho! Throw in come spices and we have one of my favorite
cold day meals :)
I know this has been written a few time online, but the last time I needed to read up on it, it took a little long to find the answer.
Below we have my current working directory that is /root, take a look at what we have in the directory:
In : import os In : os.system('pwd') /root Out: 0 In : os.system('ls -l /root') total 12 drwxr-xr-x 3 root root 4096 Dec 5 15:47 filesystems drwxr-xr-x 3 root root 4096 Dec 5 15:01 iso drwxr-xr-x 3 root root 4096 Dec 5 15:14 squashfs Out: 0
I’m then going to keep track of my current root, this part is very important:
In : real_root = os.open('/', os.O_RDONLY)
In : os.chroot('/root/squashfs/archlinux/') In : os.chdir('/root')
We are now in the new room, lets have a look around:
In : os.system('pwd') /root Out: 0 In : os.system('ls -l /root/') total 16 -rw-r--r-- 1 root root 7725 Dec 5 21:12 install.txt
And lets go ahead and back out of this chroot back up to the real root filesystem:
In : os.fchdir(real_root) In : os.chroot('.') In : os.chdir('/root')
And lets verify our old data is in place:
In : os.system('pwd') /root Out: 0 In : os.system('ls -l /root/') total 12 drwxr-xr-x 3 root root 4096 Dec 5 15:47 filesystems drwxr-xr-x 3 root root 4096 Dec 5 15:01 iso drwxr-xr-x 3 root root 4096 Dec 5 15:14 squashfs
This weekend I brushed off a few computers and setup Diablo II Lord of Destruction
for the family!
I used to play this game for days on end back in my high school years
(Loved hardcore online play). The wife even played a bit of single player,
so I figured it was time to introduce it to the kids!
Below we have the kids about to be introduced to an truly awesome RPG