Swap 2 Secrets via Homomorphic Properties of Shamir Secret Sharing

这篇具有很好参考价值的文章主要介绍了Swap 2 Secrets via Homomorphic Properties of Shamir Secret Sharing。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

The Description of the problem

I have 2 secrets denoted as s 1 , s 2 s_1, s_2 s1,s2 and they are in different vector with same dimensions. Now all the vector are encrypted by the Shamir Secret Sharing. What is I really want is to swap the s 1 , s 2 s_1, s_2 s1,s2 in their shares format via the homomorphic properties of Secret Sharing. I need you give me a python implementation.
To accomplish the task of swapping the secrets s 1 s_1 s1 and s 2 s_2 s2 without revealing them, you can use the additive homomorphic properties of Shamir’s Secret Sharing. I’ll provide a Python implementation using the secretsharing library:

The Solution from GPT-4

  1. Install the secretsharing library if you haven’t already:
pip install secret-sharing
  1. Here’s a Python implementation that demonstrates swapping the secrets s 1 s_1 s1 and s 2 s_2 s2 in their shares format:
import random
from secretsharing import PlaintextToHexSecretSharer as Sharer

def generate_shares(secret, n_shares, threshold):
    shares = Sharer.split_secret(secret, threshold, n_shares)
    return shares

def swap_shares(shares_s1, shares_s2):
    swapped_shares_s1 = []
    swapped_shares_s2 = []

    for share_s1, share_s2 in zip(shares_s1, shares_s2):
        int_share_s1 = int(share_s1.split('-')[1], 16)
        int_share_s2 = int(share_s2.split('-')[1], 16)

        # Swap the secrets using additive homomorphism
        swapped_int_share_s1 = (int_share_s1 - int_share_s2) % Sharer.prime
        swapped_int_share_s2 = (int_share_s2 + int_share_s1) % Sharer.prime
        
        swapped_share_s1 = share_s1.split('-')[0] + '-' + format(swapped_int_share_s1, 'x')
        swapped_share_s2 = share_s2.split('-')[0] + '-' + format(swapped_int_share_s2, 'x')

        swapped_shares_s1.append(swapped_share_s1)
        swapped_shares_s2.append(swapped_share_s2)

    return swapped_shares_s1, swapped_shares_s2

def recover_secret(shares):
    secret = Sharer.recover_secret(shares)
    return secret

def main():
    s1 = hex(random.randint(1, 1_000_000))[2:]  # Example secret 1
    s2 = hex(random.randint(1, 1_000_000))[2:]  # Example secret 2
    n_shares = 5
    threshold = 3

    shares_s1 = generate_shares(s1, n_shares, threshold)
    shares_s2 = generate_shares(s2, n_shares, threshold)

    print(f"Original shares:\nSecret 1: {shares_s1}\nSecret 2: {shares_s2}")

    swapped_shares_s1, swapped_shares_s2 = swap_shares(shares_s1, shares_s2)

    print(f"\nSwapped shares:\nSecret 1: {swapped_shares_s1}\nSecret 2: {swapped_shares_s2}")

    recovered_s2 = recover_secret(swapped_shares_s1[:threshold])
    recovered_s1 = recover_secret(swapped_shares_s2[:threshold])

    print(f"\nRecovered secrets after swapping:\nSecret 1: {recovered_s1}\nSecret 2: {recovered_s2}")

if __name__ == "__main__":
    main()

This implementation generates shares for two secrets, s 1 s_1 s1 and s 2 s_2 s2, and then swaps them using homomorphic properties without revealing the secrets. Finally, it recovers the secrets from the swapped shares. Note that this implementation assumes the secrets are in hexadecimal format.文章来源地址https://www.toymoban.com/news/detail-463807.html

到了这里,关于Swap 2 Secrets via Homomorphic Properties of Shamir Secret Sharing的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【JS】如何解决Cannot set properties of undefined

    TypeError: Cannot set properties of undefined 类型错误:无法设置未定义的属性 问题解析 当前的是当前对象或者数组是undefined,但是却用来引用属性或者索引 比如下面两种情况 或者是当前的value值不是我们显式声明的undefined,而是运算之后得到undefined,之后我们再去用它 解决方案 问

    2024年02月16日
    浏览(57)
  • 解决Cannot read properties of undefined (reading ‘resetFields‘)

    第一天做项目中遇到了这一个问题关于resetField重置校验报错的问题,   然后去网上查找问题的原因,但是找到问题的原因是: mouted加载table数据以后,隐藏的 Dialog 并没有编译渲染进 dom 里面。所以当通过点击事件,Dialog 弹出的时候,$refs 并没有获取到 dom 元素导致 ‘reset

    2023年04月23日
    浏览(68)
  • 解决Cannot read properties of undefined (...)类型的报错

    场景: 在项目中,想要获取鼠标的元素,红色区域报错:Cannot read properties of undefined (reading \\\'grid3D\\\') 分析: Cannot read properties of undefined类型的报错,一般是报错元素的前一个元素出了问题,也就是this.option没有获取到。 报错类型一般为两种: 对象没值的时候 对象为undefined的时

    2024年02月12日
    浏览(34)
  • 解决 Cannot read properties of undefined类型的报错

    报错类型一般为两种 对象类型 对象没有数据的时候为undefined 这个时候访问内部内容就会报错 举个例子 正常情况 对象有值的时候 var obj={name:‘张三’,age:18} #此时对象有数据访问不会报错 console.log(obj.name) 1 2 3 对象没值的时候 var obj={} console.log(obj.name) #就会报错 Uncaught Syntax

    2023年04月21日
    浏览(32)
  • 解决 Cannot read properties of null (reading ‘disabled‘)报错

    在Vue + elementUI 后台项目里遇到了一个问题,所有模块的的下拉Select 和时间选择器DataPicker (可能还有其他组件) ,在选择后点击页面其他地方都不会自己收起。打开控制台会发现报错了,每点击一次,错误+1. 代码里全局搜索 el-dropdown ,el-dropdown下缺少 el-dropdown-menu 元素,如果

    2024年02月13日
    浏览(34)
  • [已解决]Cannot read properties of undefined (reading ‘install‘)

    唉,对于计算机的bug是真的很害怕。但是这个错误,我发现解决起来还是蛮简单的。 参考这篇博客: (2条消息) 错误“Cannot read properties of undefined (reading ‘install‘) at Vue.use” 的解决方案_cannot read properties of undefined (reading \\\'inst_FunSober的博客-CSDN博客 原因主要就是我们在下载

    2024年02月13日
    浏览(32)
  • ❤ cannot read properties of null(reading appendChild)解决办法

    写的一个js渲染,但是出了个小问题,cannot read properties of null(reading appendChild)报错。 大致意思是:不能读取空的属性。 1、console.log() //打印数据内容,查看获取数据是否有问题。 2、js引入放body最后面,页面是自上而下的运行的,HTML都没有运行到,当然获取不到对应节点 3、

    2024年02月14日
    浏览(31)
  • “TypeError: Cannot read properties of null (reading ‘getContext‘)“

    目录 一、报错截图 二、使用场景 三、代码截图 四、报错原因  五、解决办法 第一次在vue项目种使用canvas,跟着网上教程做,标签canvas写好了,dom元素获取了,简单“画”了一下,运行之后报\\\"TypeError: Cannot read properties of null (reading \\\'getContext\\\')\\\"的错。 意思是:找不到getContex

    2024年02月16日
    浏览(38)
  • TypeError: Cannot read properties of undefined (reading ‘replace‘)

    错误一:TypeError: Cannot read properties of undefined (reading \\\'replace\\\') 错误二:[Vue warn]: inject() can only be used inside setup() or functional conponents. 解释:当我们使用内置 use开头的钩子函数时,不能进行嵌套去拿实例。如: 解决:必须在 setup函数 第一层调用。

    2024年02月11日
    浏览(35)
  • TypeError: Cannot read properties of undefined (reading ‘map‘)

    控制台报错 TypeError: Cannot read properties of undefined (reading \\\'map\\\') 我的错误原因: 第一次页面渲染的时候,map的对象是undefined或null, 解决方法: 在前面加个要进行判断,当有值时再去遍历

    2024年02月07日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包