# How can I make sure message m ∈ Zp

I am implementing ORUTA and using JPBC library for it.
In one of the algorithms, for hashing a message, it is specified that for message m:

$m \in \mathbb Z_p$ , for some large prime $p$.

I have a message text, so how can I make sure that the above equation holds true?
(If possible someone please reply with example code or any predefined funtion able to do this).

• We won't answer you how you can do this with your favorite library, but rather how it is done in theory. If you want code, you have to ask on StackOverflow. – SEJPM Mar 2 '17 at 11:54

This test is really quite simple (this is the theoretical base, not code because this is not StackOverflow):

1. You convert your byte-array m into the integer $m$ according to your applicable standard
2. $$m\in\mathbb Z_p\iff 0\leq m \land m < p$$ So in order for an integer $m$ to be in the additive group $\mathbb Z_p$ it needs to be non-negative ($\geq 0$) and smaller than $p$.
3. Bonus: If you're looking for membership of the multiplicative group instead of the additive group: $$m\in\mathbb Z^*_p\iff m\in\mathbb Z_p\land m\neq 0\iff 0<m\land m<p$$ So in order for an integer to be in the multiplicative group $\mathbb Z^*_p$ it needs to be in the additive group and not be $0$ or (equivalently) it needs to be positive ($>0$) and smaller than $p$.

Note that this all only applies when $p\in\mathbb P$ is a prime.

• This does depend very much on your representation of $\mathbb{Z}_p$, which doesn't have to be the set $\{0,\ldots,p-1\}$. Although in crypto-world this is usually what people use. – CurveEnthusiast Mar 2 '17 at 12:56

It depends on what exactly you want to achieve. I don't know ORUTA.

But in general: You have to convert your message to a numerical representation somehow. Then the message has to be short enough to be in Zp.

e.g. in Java:

    BigInteger p = [your p value]
String message = "test message";
BigInteger m = new BigInteger(1,message.getBytes(StandardCharsets.UTF_8));
if(m.compareTo(p)>0) {
not good, your message is too big!
}


Usually in signature schemes, you use the hash value of the message instead of the message, because a hash function has a fixed output size and for a suitable p you can be certain it is always < p.

This is also quite simple, but if you say you want to compute a hash, it is probably not what you want to do?

• Both answers solved my doubt.. but unfortunately, I can mark only one as answer. Thank you so much. – Kashyap Kotak Mar 3 '17 at 3:42