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 Sharerdef generate_shares(secret, n_shares, threshold):shares = Sharer.split_secret(secret, threshold, n_shares)return sharesdef 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 homomorphismswapped_int_share_s1 = (int_share_s1 - int_share_s2) % Sharer.primeswapped_int_share_s2 = (int_share_s2 + int_share_s1) % Sharer.primeswapped_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_s2def recover_secret(shares):secret = Sharer.recover_secret(shares)return secretdef main():s1 = hex(random.randint(1, 1_000_000))[2:]  # Example secret 1s2 = hex(random.randint(1, 1_000_000))[2:]  # Example secret 2n_shares = 5threshold = 3shares_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.

Swap 2 Secrets via Homomorphic Properties of Shamir Secret Sharing相关推荐

  1. 私钥分割 — Shamir Secret Sharing

    在做区块链应用的时候,最常碰到的一个问题就是,怎么保管私钥,怎么让使用者方便,但又同时是安全的.第一个想法就是备份密钥(不论是passphrase/keystore/私钥),但是如果把使用者密钥(加密 ...

  2. [3th of series ABE] Shamir‘s Secret Sharing

    Abstract This blog is going to discuss Shamir's Secret Sharing Scheme. 1. Polynomial Interpolation 给 ...

  3. secret sharing;拉格朗日插值,shamir秘密分享,peterson秘密分享

    秘密分享 系统中为了将秘密s在参与方 p 1 , p 2 , . . . , p n {p_1,p_2,...,p_n} p

  4. python的秘密_Shamir秘密共享方案 (Python)

    Shamir's Secret Sharing scheme is an important cryptographic algorithm that allows private informati ...

  5. 名词解释:Web3 账户相关概念大梳理

    刚刚结束的 Devcon 上,账户抽象算是是最热的几个话题之一,最近可以经常看到 AA / EOA / SCW / 4337 等缩写和代号在各种 talk.panel 和信息流里出现.再加上叙事开始往 ...

  6. 光盘 机密_使用保险柜管理机密

    光盘 机密 您如何存储秘密? 密码,API密钥,安全令牌和机密数据属于秘密类别. 那是不应该存在的数据. 在容易猜测的位置,不得以纯文本格式提供. 实际上,不得在任何位置以明文形式存储它. 可以使用S ...

  7. 第二十一届国际C语言混乱代码大赛结果公布

    摘要:国际C语言混乱代码大赛(IOCCC, The International Obfuscated C Code Contest)是一项著名的国际编程赛事,从1984年开始到2006年,每年举办一次 ...

  8. Compact Multi-Signatures for Smaller Blockchains代码解析

    1. 引言 Boneh等人2018年论文<Compact Multi-Signatures for Smaller Blockchains>,论文解读参见博客 Compact Multi- ...

  9. Verifiable Secret Sharing

    参考文献: Feldman P. A practical scheme for non-interactive verifiable secret sharing[C]//28th Annual Sy ...

最新文章

  1. 简单创建vsftp server
  2. 网页实时聊天之PHP如何实现websocket
  3. LeetCode-链表-206. 反转链表
  4. 调用BAPI_MATERIAL_SAVEDATA批量创建/修改物料
  5. jquery_pagination分页插件的使用
  6. npm查看指定包的所有版本
  7. Restlet入门示例
  8. 新记录 Core 2 Duo E8600 被超频到6.25GHz
  9. linux脚本嵌套,linux shell 嵌套expect 与服务器交互脚本
  10. 深度学习——初识TensorFlow
  11. HNOI2019:My Dream
  12. 经典的CSS代码(转)
  13. 西安交通大学网络教育计算机考试题,西安交通大学《大学计算机基础》理论考试试题.doc...
  14. jQuery实现表格冻结行和列
  15. Java精简高效异步编程实战
  16. python对seo有什么用_python对seo的帮助 – python对seo的帮助是什么?- 企业服务
  17. 01-探寻 JavaScript 反爬虫的根本原因
  18. nginx启动提示nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  19. Python之Scikit-Learm
  20. CAN总线基础知识点

热门文章

  1. 5款优秀的开源克隆软件
  2. C#ABB机器人PC SDK 通讯05
  3. Python模拟星空
  4. android整合好视通sdk经验总结(二)
  5. nginx设置 页面 301 跳转
  6. Python调用百度OCR实现图片文字识别
  7. FFmpeg:进行qsv加速转码,以及如何动态更改编码器的选项(附完整源代码)
  8. 一个扑街自媒体人的自白:我曾经月入15000,却是昙花一现
  9. 苹果手机充电越充越少是怎么回事_手机充电时充电器发热怎么回事
  10. 记录遇到的问题之---把16进制的颜色rgb转换成‘#’形式