Bitwise Operators And Blowfish

March 8, 2007

I wrote a while back about writing my own Blowfish/Twofish implementation in JavaScript, but lamented that I didn’t know enough about JS to pull it off. Well, I still don’t know enough about JS to do it, but it turns out I don’t know enough about C++ to do it either. Yesterday I tried writing my own blowfish encrypt, and got very stuck after my third iteration.

What was I missing that I needed to get it done? Bitwise operators and data type knowledge. I spent some time today writing a few programs to test bitwise operators and try to understand whats going on. The ones that gave me the most trouble were the shift operators. For some reason I had it firmly in my mind that they acted like shift registers (think hardware). I kept trying to shift one number into another bit by bit.

Only when I set up some runs and included a binary printout after each step did it actually click what was going on with those operators. I felt silly.

Anyway, here’s a link to the source of my little bitwise operator (mostly shifts) example. I didn’t write that binary printer BTW. I did, however, write that code highlighter system using GeSHi, which rocks.

bitwise.cpp

Blowfish Version 1
version001.cpp

Blowfish Version 2
blowfish.cpp
blowfish.h
tester.cpp

Blowfish Version 3
blowfish.cpp
blowfish.h
tester.h

Categories: Geek
Tags: , , ,

Leave A Comment

Your email will not be published.