This encryption algorithm is not secure at all, in fact it was made for educational purposes. It uses a 10-bit key that can be quickly broken by a brute force attack. But, who knows, it may be good for someone interested in some quick encryption where security is not that important, or for embedded devices were resources are limited, or just for lazy students. 😀
So, here is my version of the S-DES algorithm in plain C. Differently from this other version in the web my implementation is more byte-oriented while the other (probably more didactic) is converting the input to a string with ‘0’s and ‘1’s and working over it. Also, there is another implementation that uses some C++ functions while mine is written in plain C.
You can take a look at the code online (it is less than 300 lines) — released under BSD license.
To build it with gcc type:
Note that I’m using math library only because of the pow() function that is used only in debug mode.
Includes a paper by William Stallings explaining the algorithm.