1

I'm trying out an algorithm for cryptolology. The process should have been simple:

It secures a message msg = b'Sample' by passing IPI points, let's say: ipi = np.array([1,2,3,4,5])

Via RSCodec by encoding the message a polynomial coefficient is generated. And by passing IPI points through the polynomial it generates a vault at the end of the process.

This was successful. It generates a vault (N,2) - shaped np.int64 matrix representing set of x and y coordinates.

However when decoding the message the problem occurs. So in order to recover the message, all I had to do was.

  1. corresponding y - coordinates lookup per and x coordinate. This returns a set of (x,y) represented as np.64 matrix.

  2. By using the points generated in step 1, I try to recover the polynomial coefficients by decoding it by computing lagrange interpolating polynomial coefficients.

  3. Finally, now that I got the polynomial coeffs, I decode it via RScodec once again hoping to get back the message that was decoded. However I'm getting empty instead. a simple rs.decode()

So a shortened snippet of my snippet would be:

Decode

def get_points(ipi, vault):
    ixs = np.in1d(vault[:,0], ipi)
    points = vault[ixs]
    return points

def decode_coefficients(points):
    xs = points[:,0]
    ys = points[:,1]
    coeffs = poly_to_coeffs(lagrange(xs,ys))
    # return as bytearray:
    return bytearray(coeffs.astype(int).tolist())

For encoding its quite simpler:

def encode(msg, ipi):
  coefficients = rs.encode(msg)
  vault = projection(coefficients, ipi)
  return vault

def projection(coeffs, ipi):
  y = np.polyval(coefffs,ipi).astype(np.int64) % modulus
  return np.stack([ipi,y], axis=1)

This is some logs from my testing.

msg = b'Sample'
ipi = np.array([1,2,3,4,5])




Generate fuzzy vault: bytearray(b'Sample')
[[ 10 100]
 [ 57  70]
 [ 66  83]
 [ 65 160]
 [ 21  34]
 [  5 100]
 [ 24 145]
 [ 53  16]
 [  4   2]
 [ 36   2]
 [  9  59]
 [ 38 183]
 [  2 154]
 [ 67 167]
 [  3 108]
 [ 62  58]
 [ 74   7]
 [ 18  31]
 [  1  84]
 [  6 186]
 [ 11 111]
 [ 46 166]
 [ 32 127]]
Process finished in: 0.04680013656616211

-------------------------Unlocking vault

Unlocked fuzzy vault:   
bytearray(b'')

I'm just coding around for learning. What am I doing wrong?

What I tried so far:

  1. Switching over to unireedsolomon.
  2. Using reedsolo library directly (not using RSCodec) - import reedsolo as rs
  3. Calibrating erase_pos
deku
  • 131
  • 10
  • I don't know Python very well, but I am familiar with RS codes. Looking at your example code, how does polyval(..., ipi) return more than the 5 elements in ipi? Polyval would need to operate within a Galois field, I don't know if that is what happens in your code. If rs.encode(msg) generates N coefficients, then you need to use Galios field type polyval() on N+1 (or more) data points in order for a Galois field type Lagrange interpolation to produce a unique N coefficient polynomial. – rcgldr Jul 21 '18 at 20:19
  • @rcgldr I am trying to replicate the same function without gf's. As you have said, I can generate N coefficients with encoding, and N data points throwing it to the lagrange interplortation. Beause isn't N+1 encoding, has to be solved with N+1 decoding? Not sure... im a newb in RS codes as I have said im trying it out thus im going with the simplest form as possible. Perhaps can you demonstrate how you would do it? Im getting your point and have reread the textbook. Even if the snippet is made on another language. Or just the flow perhaps? – deku Jul 21 '18 at 20:32
  • Let m = number of elements in msg. Assuming rs.encode() is systematic, then the first m coefficients of the encoded message will be the message. There would be no need to decode. – rcgldr Jul 21 '18 at 20:33
  • 1
    I don't see a need for RS code with this approach. The message of size m could be treated as the coefficients to a polynomial of degree m-1. Then the polynomial could be used to calculate m values based on some unknown to anything but the encoder and decoder set of input values for polyval(). The issue here is that these values could be huge and using % modulus will break the ability to use Lagrange to recover the polynomial. For this approach, you'll probably need to use gf based functions. – rcgldr Jul 21 '18 at 20:50
  • what im trying out here is decoding a message wtih IPI that has been turned into a polynomial coefficient turned into a projection. To decode that what im accepting is that projection itself. Then turn it into a a coeff again and decode to get back the message. I came up with an idea using what you have suggested, the N+1 one, ( I did this to the projection, then turned it into coeffs, then decoded ) however im still getting the same empty bytearray which means it was wrong, or the interplotation is very far for reed to decode. Can you give suggestion based on what I have said in this cmmnt? – deku Jul 21 '18 at 21:12
  • Conversing with you im getting near with the implementation. Indeed %moudlus breaks the ability to use lagrange. However I need to turn these polynomials to coefficients, for that I need lagrange right? Plus if I * the amount of modulo I used for encoding, it should be able to cancel that effect. it should be possible to get nearer. Actually I just tried it now, and the coefficient generated is nearer than before, but not enough to generate what been encoded, im still using lagrange. What do you supposed I use to generate polynomials id not lagrange? – deku Jul 21 '18 at 21:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176496/discussion-between-deku-and-rcgldr). – deku Jul 21 '18 at 21:25

1 Answers1

0

Looking at it, I think I saw something similar before but it was using Galois fields, but don't you need to to get the subset of the retrieved points first? Before throwing it to the decode_coeff function?

Rekt
  • 359
  • 2
  • 18