What is the error in this?

function DECout = gf2dec(HA)
c=0:[(2^8)-1];
GFRefarray=gf(c);
for i=1:length(HA)
for k=0:(2^8)-1
temp=isequal(HAHA(i),GFRefarray(i));
if (temp==1)
DECout(i)=k;
end
end
end
The error is: >> gf2dec Error using gf (line 65) X must be between 0 and 2^m-1
Error in gf2dec (line 3) GFRefarray=gf(c); How to solve this??
The value of HA is:
HA = GF(2^8) array. Primitive polynomial = D^8+D^4+D^3+D^2+1 (285 decimal)
Array elements =
172
106
200
187
68
251
103
2
149
131
25
55
237
110
129
231
I am trying to convert the galois polynomial, HA into a numeric value. I want to encrypt the data. So, how can I convert this ?

Answers (1)

>> help gf
gf Create a Galois field array.
X_GF = gf(X,M) creates a Galois field array from X in the field
gf(2^M), for 1<=M<=16. The elements of X must be integers between 0
and 2^M-1. [...]
X_GF = gf(X) uses a default value of M = 1.

9 Comments

Sir, I tried editing this line: c=0:[(2^8)-1]; replaced 8 by 1,because by default is 1. Even then i got an error stating, not enough arguments. Is that what you meant??
Sir, i got the error rectified, but still conversion is not happening?? What might be the issue??
function DECout = gf2dec(HA)
N = 8;
c = 0 : (2^N)-1;
GFRefarray = gf(c, N);
for i = 1:length(HA)
for k = c
if isequal(HAHA(i),GFRefarray(i));
DECout(i)=k;
end
end
end
... looks pretty inefficient to me.
Sir, could you please help. I tried the above code too. I am still not able to convert the galois polynomial into a hexadecimal value. Could you please help with the correct code?
function DECout = gf2dec(HA)
N = 8;
c = 0 : (2^N)-1;
GFRefarray = gf(c, N);
for i = 1:length(HA)
for k = c
if isequal(HA(i),GFRefarray(k+1));
DECout(i)=k;
end
end
end
HA = GF(2^8) array. Primitive polynomial = D^8+D^4+D^3+D^2+1 (285 decimal)
Array elements =
172
106
200
187
68
251
103
2
149
131
25
55
237
110
129
231
The error is : gf2dec Error using gf2dec (line 18) Not enough input arguments. line 18 is this : for i=1:length(HA) How to correct this sir?
You would get that error if you did not pass HA to gf2dec.
result = gf2dec(HA)
I would note that the code from the other thread, accessing the properties of the field, would be a lot more efficient.
Yes, that is right sir. But HA is obtained from hash1(g) which is again a function. How to call a functon within a function??
Very sorry Sir, now I got the error rectified. I made a mistake while calling functions. Thanks a lot sir.

Sign in to comment.

Asked:

on 3 Jan 2018

Commented:

on 10 Jan 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!