How are Rijndael's S-Boxes generated?
In your code you use the modular inverse with the respect to the modulus 0x11b, which is an operation quite different from taking the inverse in the field GF(2^8).

For getting an idea what you have to do instead, take a look at finite field arithmetic in the wikipedia.