7

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!

4

1 回答 1

18

您可以使用XOR 密码,它非常简单:

E(x,key)=> y= x XOR key
D(y,key)=> x= y XOR key

很简单!

您可以升级加密并使其成为密码块链接,这意味着例如您有一个数据 D,您需要将其划分为块,比如说大小为 B 的块。对于您执行的第一个块:

E(b0,key)=> y0= b0 XOR key

结果将成为下一个块加密的关键:

E(b1,y0)=> y1= b0 XOR y0 .... E(bn,yn-1)=> yn= bn XOR yn-1

在此处输入图像描述

原始数据D={b0,b1.....bn}和加密数据现在E={y0,y1....yn} 要解密加密数据,您需要以相反的方式进行操作!就这样!

于 2013-04-25T15:54:26.830 回答