Christine Allen
Christine Allen

Reputation: 37

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

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?

Upvotes: 0

Views: 97

Answers (2)

Christine Allen
Christine Allen

Reputation: 37

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']

Upvotes: 0

Christine Allen
Christine Allen

Reputation: 37

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']

Upvotes: 1

Related Questions