Q:

Simple Encryption Algorithm

I'm working on an elevator project just for fun, it's actually hardware.  But I think this is more of a software question.  I don't need to have this feature, in fact it is completely redundant, but I was curious so I'm adding it anyway so I can learn :P
I have an 8 bit address, 8 bit data bus, and an 8 bit encryption code.
I have a master and many slave devices.
The master knows the address of the slaves and knows the encryption code.
The slaves know their address and the encryption code as well.
I want a really simple algorithm such that:
The master sends "y" where, y = function(data,encryption code)
The slave receives "y" and can extract data by data = function2(y,encryption code)
I tried playing around with AND, XOR, OR, etc... and combinations of them, but couldn't figure it out.
Again I'm looking for simple algorithms.  If you don't mind you could do me a bigger favour and explain some theory on how I can come to such a solution/functions.
Thanks so much!

A:

You can use XOR cipher it's very simple:
E(x,key)=> y= x XOR key
D(y,key)=> x= y XOR key

very simple!
You can upgrade the encryption  and to make it to cipher-block chaining that means  for example you have a data D you need to divide it to blocks, let say block of size B. for the first block you do:
E(b0,key)=> y0= b0 XOR key

the result its going to be the key for the next block encryption:
E(b1,y0)=> y1= b0 XOR y0 .... E(bn,yn-1)=> yn= bn XOR yn-1

The original data was D={b0,b1.....bn} and the encrypted data its now E={y0,y1....yn}
to decrypt the encrypted data you need to do the opposite way! that's all! 

