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.
corresponding y - coordinates lookup per and x coordinate. This returns a set of (x,y) represented as np.64 matrix.
By using the points generated in step 1, I try to recover the polynomial coefficients by decoding it by computing lagrange interpolating polynomial coefficients.
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:
- Switching over to unireedsolomon.
- Using reedsolo library directly (not using RSCodec) -
import reedsolo as rs
- Calibrating
erase_pos