# 如何实现一个去中心化的 Dropbox 存储

Merkle Trees 与 Challenge-Response 协议

M of N

1 * a + b = 13
2 * a + b = 21

a = 8

b = 5

a * 1 ^ 3 + b * 1 ^ 2 + c * 1 + d = 1
a * 2 ^ 3 + b * 2 ^ 2 + c * 2 + d = 3
a * 3 ^ 3 + b * 3 ^ 2 + c * 3 + d = 2
a * 4 ^ 3 + b * 4 ^ 2 + c * 4 + d = 1

a * 7 + b * 3 + c = 2
a * 19 + b * 5 + c = -1
a * 37 + b * 7 + c = -1
a * 12 + b * 2 = -3
a * 18 + b * 2 = 0
a * 6 = 3

1/2 * 12 + b * 2 = -3

1/2 * 7 - 9/2 * 3 + c = 2

1/2 - 9/2 + 12 + d = 1

> import share
> share.sys_solve([[1.0, 1.0, 1.0, 1.0, -1.0], [8.0, 4.0, 2.0, 1.0, -3.0], [27.0, 9.0, 3.0, 1.0, -2.0], [64.0, 16.0, 4.0, 1.0, -1.0]])
[0.5, -4.5, 12.0, -7.0]

> import share
> share.lagrange_interp([1.0, 3.0, 2.0, 1.0], [1.0, 2.0, 3.0, 4.0])
[-7.0, 12.000000000000002, -4.5, 0.4999999999999999]

> share.eval_poly_at([-7.0, 12.0, -4.5, 0.5], 5)
3.0。
> share.eval_poly_at([-7.0, 12.0, -4.5, 0.5], 6)
11.0
> share.eval_poly_at([-7.0, 12.0, -4.5, 0.5], 7)
28.0

> def fac(n): return 1 if n==0 else n * fac(n-1)
> def choose(n,k): return fac(n) / fac(k) / fac(n-k)
> def prob(n,k,p): return choose(n,k) * p ** k * (1-p) ** (n-k)

> sum([prob(60, k, 0.5) for k in range(0, 20)])
0.0031088013296633353

> share.lagrange_interp([1.0, 3.0, 2.0, 5.0], [1.0, 2.0, 3.0, 4.0])
[-11.0, 19.333333333333336, -8.5, 1.1666666666666665]

> map(lambda x: share.eval_poly_at([-7.0, 12.0, -4.5, 0.5], x), [1, 2, 3, 4, 5, 6])
[1.0, 3.0, 2.0, 1.0, 3.0, 11.0]
> share.berlekamp_welch_attempt([1.0, 3.0, 18018.0, 1.0, 3.0, 11.0], [1, 2, 3, 4, 5, 6], 3)
[-7.0, 12.0, -4.5, 0.5]
> share.berlekamp_welch_attempt([1.0, 3.0, 2.0, 1.0, 3.0, 0.0], [1, 2, 3, 4, 5, 6], 3)
[-7.0, 12.0, -4.5, 0.5]

a + b := (a + b) % 11
a - b := (a - b) % 11
a * b := (a * b) % 11
a / b := (a * b ** 9) % 11

> e = share.mkModuloClass(11)
> P = share.lagrange_interp(map(e, [1, 3, 2, 1]), map(e, [1, 2, 3, 4]))
> P
[4, 1, 1, 6]
> map(lambda x: share.eval_poly_at(map(e, P), e(x)), range(1, 9))
[1, 3, 2, 1, 3, 0, 6, 2]
> share.berlekamp_welch_attempt(map(e, [1, 9, 9, 1, 3, 0, 6, 2]), map(e, [1, 2, 3, 4, 5, 6, 7, 8]), 3)
[4, 1, 1, 6]

map(e, [v1, v2, v3]) 用来转变普通的整数到新域里的元素；该软件库包含了一种对 11 取余类的实现，该类提供了无缝的算术操作接口，所以我们能够互换它们，例如 print e(6) * e(6) 返回 3。你可以看到，所有的一切仍然工作 - 除了那个，因为我们对加减乘除操作进行了重新定义，因此所有的操作返回的整数都在 [0 ... 10] 范围内。我们从不需要担心浮点数精度问题或者是当 x 轴变大之后，相应 y 轴值变得无限大。

> P1 = share.lagrange_interp(map(share.Galois, [ord("a"), ord("e"), ord("i")]), map(share.Galois, [1, 2, 3]))
[109, 253, 241]
> P2 = share.lagrange_interp(map(share.Galois, [ord("b"), ord("f"), ord("j")]), map(share.Galois, [1, 2, 3]))
[110, 253, 241]
> P3 = share.lagrange_interp(map(share.Galois, [ord("c"), ord("g"), ord("k")]), map(share.Galois, [1, 2, 3]))
[111, 253, 241]
> P4 = share.lagrange_interp(map(share.Galois, [ord("d"), ord("h"), ord("l")]), map(share.Galois, [1, 2, 3]))
[96, 4, 0]

> map(lambda x : share.eval_poly_at(map(share.Galois,P1),share.Galois(x)), range(1, 7))
[97, 101, 105, 61, 49, 53]
> map(lambda x : share.eval_poly_at(map(share.Galois,P2),share.Galois(x)), range(1, 7))
[98, 102, 106, 62, 50, 54]
> map(lambda x : share.eval_poly_at(map(share.Galois,P3),share.Galois(x)), range(1, 7))
[99, 103, 107, 63, 51, 55]
> map(lambda x : share.eval_poly_at(map(share.Galois,P4),share.Galois(x)), range(1, 7))
[100, 104, 108, 112, 116, 120]

> share.berlekamp_welch_attempt(map(share.Galois,[97, 101, 105, 61, 4, 5]), map(share.Galois,[1, 2, 3, 4, 5, 6]), 2)
[109, 253, 241]

> map(chr, [97, 101, 105, 61, 49, 53])
['a', 'e', 'i', '=', '1', '5']
>map(chr, [98, 102, 106, 62, 50, 54])
['b', 'f', 'j', '>', '2', '6']
> map(chr, [99, 103, 107, 63, 51, 55])
['c', 'g', 'k', '?', '3', '7']
> map(chr, [100, 104, 108, 112, 116, 120])
['d', 'h', 'l', 'p', 't', 'x']

> P1 = share.lagrange_interp(map(share.Galois,map(ord, ["a", "=", "1"])), map(share.Galois, [1,4,5]))
[109, 253, 241]
> P2 = share.lagrange_interp(map(share.Galois,map(ord, ["b", ">", "2"])), map(share.Galois, [1,4,5]))
[110, 253, 241]
...
> map(lambda x : share.eval_poly_at(map(share.Galois,P1),share.Galois(x)), range(1, 4))
[97, 101, 105]  -> ["a", "e", "i"]
...

> share.lagrange_interp([1.0, 3.0, 2.0, 1.0], [1.0, 2.0, 3.0, 4.0])
[-7.0, 12.000000000000002, -4.5, 0.4999999999999999]
> share.lagrange_interp([10.0, 5.0, 5.0, 10.0], [1.0, 2.0, 3.0, 4.0])
[20.0, -12.5, 2.5, 0.0]
> share.lagrange_interp([11.0, 8.0, 7.0, 11.0], [1.0, 2.0, 3.0, 4.0])
[13.0, -0.5, -2.0, 0.5000000000000002]
> share.lagrange_interp([22.0, 16.0, 14.0, 22.0], [1.0, 2.0, 3.0, 4.0])
[26.0, -1.0, -4.0, 1.0000000000000004]

1  3
2  1

1  3  5  7
2  1  0  10
3  10
4  8

1  3  5  7
2  1  0  10
3  10 6  2
4  8  1  5

In [77]: e = share.mkModuloClass(11)

In [78]: share.extend([1,3],2,e)
Out[78]: [1, 3, 5, 7]

In [79]: share.extend([2,1],2,e)
Out[79]: [2, 1, 0, 10]

In [80]: share.extend([1,2],2,e)
Out[80]: [1, 2, 3, 4]

In [81]: share.extend([3,1],2,e)
Out[81]: [3, 1, 10, 8]

In [82]: share.extend([5,0],2,e)
Out[82]: [5, 0, 6, 1]

In [83]: share.extend([7,10],2,e)
Out[83]: [7, 10, 2, 5]

In [90]: share.repair([5,0,None,1],2,e)
Out[90]: [5, 0, 6, 1]

In [94]: share.repair([3,10,None,2],2,e)
Out[94]: [3, 10, 6, 2]

the cube can still function even if up to 78% of it were to be destroyed...

Secret Sharing

• 点赞 4
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

跨链技术践行者

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文
01-21 9485

05-15 1万+
05-11 9535
05-13 1万+
12-13 1万+
09-24 1320
08-21 92
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie