blog/ notes/ projects/ colophon

a.k.a (Caesar Cipher)

update 2009/01/09 : I made a JavaScript version you can play with.

There was a text advert on Daring Fireball which seemed to be obviously a shifted text. (i.e. the rotation of an intelligible text was used). That prompted me to try and decode it. I'm lazy, so i didn't want to do it by hand. The scripting laguage that I currently use is php, so I looked for a text rotation method in php, but the only one I could find is rot_13, which rotates the text by 13, but that didn't give me the answer. So I coded my own arbitrary rotation function. Here it is :

$str="Ztte pc tnt dc BprWtxhi iwxh lttz. Hdbtiwx cv’h vdxcv sdlc…";
$rot = 11;
print "rotation = $rot . Rotated text: ". rot_n($str,$rot) . "\n";
function rot_n($str,$rot){
    $upperOffset = 65;
    $lowerOffset = 97;
    $ret="";
    for($i=0; $i<strlen($str); $i++){
        $c = ord(substr($str,$i,1));
        if($c>64 && $c < 91){
            $ret.=chr(($c-$upperOffset+$rot)%26+$upperOffset);
        }
        else {
            if( $c>96 && $c<123){
                $ret.=chr(($c-$lowerOffset+$rot)%26+$lowerOffset);
            }else {
                $ret.=chr($c);
            }
        }
    }
    return $ret;
}

You can use this to code and decode :-). Maybe i'll do a javascript version of this function.Done and commited in github.

moved to the notes section : nnmc status

My wife and I went to see "In Bruges" and "Happy-go-lucky". These movies are proofs that there Hollywood should not be all that matters. They prove that "Hollywood-sized" budgets are not necessary to make good movies. You can just have good actors play well and deliver a good screenplay, You don't need slow-motion or wobbly shoulder camera for every bullet shot. You don't need a gag every 5 seconds or someone getting kicked in the nuts every other minute to smile or laugh.

Similarly, you don't need over-made-up blond bimbo spending time and fortunes in shopping and dreaming of the white kinght for a romantic comedy. You can just have good actresses playing the elementary school teachers, busy with their life. Not everything needs to always be pink all the time or dark all the time. Pastel colors exits too.

At work we have a cooperative based on the honor system. You take a drink or a snack, then you put one cross per item in a grid in front of your name.

I was bored with this array of X. So I started drawing little symbols and other stuff to change from the X. When the grid changed, I had to think about something else, and I remembered the math lessons. So my next sequence of number was the digits of PI, and now I am searching for the digits of e.

I went to the wikipedia entry, then tried the math.e python, and finally a colleague gave me e to the 50,000 digit. That's a lot of snacks.

I am now trying to find the next number or sequence to use for the next refill of the fridge.

For future references, here is e to the 20th digit from wikipedia:
2.71828 18284 59045 23536

and from Piguy's Math Page, e to the 50th digit:
2.71828 18284 59045 23536 02874 71352 66249 77572 47093 69995

Today i had to make a java program work, and it was spewing out a lot of errors, most of which can be explained by external causes (trying to connect to servers which are currently down). So i have a log file, containing traces, exception stacks etc... : a lot of stuff is repeated . So how can i weed out the uninteresting ?

well first , remove the duplicates. option a : write a perl script to do that.
option b : ask a friend if there is a simpler way .

option b tends to work quite often in my office: it turns out there of course is a unix/linux/cygwin command to do just that : uniq!

But the manual says that it works only on sequential lines, and I have dates in that log file. how do i cut out the date part ? well, option b to the rescue : just use cut!

So after cut you have lines which can be uniq'd , if only they were sorted. Well it turns out there is a sort command ! who would have thought ;).

so: first you cut then you sort, then you uniq passing each other through ... pipes of course :).

cut -f 2 -d , test.txt | cut -b 4- | sort | uniq
cut -f 2 text -d ] test.txt | sort | uniq

test that it is possible to add some text


blog/ notes/ projects/ colophon