【问题标题】:How to convert python integers to a number in ZP group in Charm-Crypto?如何将 python 整数转换为 Charm-Crypto 中 ZP 组中的数字?
【发布时间】:2017-08-03 20:23:14
【问题描述】:

我想将整数转换为 ZP 组中的数字。我编写了以下代码,但它返回了许多 <class 'integer.Element'> 类型。谁能告诉我该怎么做?

num= 193857774579808121448
bb= Conversion. IP2OS(num,  20)
ele= Conversion.OS2IP(bb, element=True) 

【问题讨论】:

  • 当你这样做时会发生什么?有没有错误?
  • 它不会产生任何错误但结果元素不是Zr组的元素,它仍然是一个python整数。

标签: python encoding cryptography integer charm-crypto


【解决方案1】:

您可以使用PairingGroup.init(ZR, 193857774579808121448) 将 Python 整数转换为 Z 中的 Charm 元素r。

例子:

>>> from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,GT,pair
>>> group = PairingGroup('SS512')
>>> i = group.init(ZR, 193857774579808121448)
>>> i
193857774579808121448
>>> type(i)
<class 'pairing.Element'>

请记住,您传入的 Python 整数必须小于配对参数中显示的 r(即 group.__dict__)。 Charm 会默默地将模运算符应用于传递的数字,以便结果元素位于 Zr 中。

【讨论】:

    猜你喜欢
    • 2017-06-07
    • 2022-11-14
    • 1970-01-01
    • 2016-01-25
    • 2015-08-23
    • 2012-07-11
    • 1970-01-01
    • 2021-02-01
    相关资源
    最近更新 更多