在Charm-crypto中如何将Python整数转换为integer.Element模N?

huangapple go评论58阅读模式
英文:

How to convert a python integer to a integer.Element mod N in Charm-crypto?

问题

我想将Python整数转换为Charm-crypto中的integer.Element mod N,但我不知道如何做。

我发现了Conversion类,它说它的输入类型可以是bytes, Bytes, int, Integer Element, Modular Integer Element,输出类型可以是int, Group element, Integer element, Integer element mod N,但我找不到将int转换为Integer element mod N的方法。有人知道如何做吗?

英文:

I want to convert a python integer to a integer.Element mod N in Charm-crypto, but I don't know how to do this.
I found the Class of Conversion that said its input types can be bytes, Bytes, int, Integer Element, Modular Integer Element and output types can be int, Group element, Integer element, Integer element mod N, but I can't find a way to convert a int to a Integer element mod N. Anyone knows how to do it?

I want to convert a python integer to a integer.Element mod N in Charm-crypto, but I don't know how to do this.
I found the Class of Conversion that said its input types can be bytes, Bytes, int, Integer Element, Modular Integer Element and output types can be int, Group element, Integer element, Integer element mod N, but I can't find a way to convert a int to a Integer element mod N. Anyone knows how to do it?

答案1

得分: 1

我已解决了这个问题,参考了网站:https://python.hotexamples.com/examples/charm.integer/-/integer/python-integer-function-examples.html
通过使用Conversion()得到integer.Element后,只需手动进行模运算,就可以得到整数元素模 N。就是这么简单!

示例:

a = 123
bb = Conversion.IP2OS(a, 20)
ele = Conversion.OS2IP(bb, element=True)
aa = ele % mpk['p']
英文:

I have solved the problem, referred to the website:https://python.hotexamples.com/examples/charm.integer/-/integer/python-integer-function-examples.html
After getting the integer.Element by using Conversion(), then just modular manually, you will get integer Element mod N. It's that simple!

Example:

a = 123
bb = Conversion.IP2OS(a, 20)
ele = Conversion.OS2IP(bb, element=True)
aa = ele % mpk['p']

答案2

得分: 0

令人惊讶!根据上面的答案,我找到了将普通整数转换为模N的整数元素的最简单方法。那就是

integer(123) % mpk['p']
英文:

Surprising!

Motivated by above answer, I found the simplest method to convert a normal int to a integer element mod N.
That is

integer(123) % mpk['p']

huangapple
  • 本文由 发表于 2023年2月19日 19:49:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75499927.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定