How to do galois multiplication?

Suppose I have 2 cell array inputs as shown below:
A={'fe' 'ff' 'e9' '92' '86' '65' '73' '1c' '6d' '6a' '8f' '94' '67' '30' '83' '08'};
H={'b8' '3b' '53' '37' '08' 'bf' '53' '5d' '0a' 'a6' 'e5' '29' '80' 'd5' '3b' '78';
How to muliply these inputs using galois field multiplication?? Can somebody helpme?

 Accepted Answer

If you have the Communications System Toolbox, please try the following script.
% Convert to GF(2^8)
gfA = gf(hex2dec(A),8);
gfH = gf(hex2dec(H),8);
% Multiplication in GF(2^8) field
gfAH = gfA .* gfH;

10 Comments

I got this error, when i did this:
Error: File: hash1.m Line: 19 Column: 5
The expression to the left of the equals sign is not
a valid target for an assignment.
Line 19 is, gfA = gf(hex2dec(A),8);
What to do ??
Seems strange... Let me check two points.
1) Has the Communications System Toolbox been already installed ?
2) What is your MATLAB version?
The error was solved. It was a minor mistake of missing a semi-colon. The code is correct. Can i convert the final answer, ie, gfA into a hexa decimal value?? I tried dec2hex(gfA), but i got an error. what should i do?
Since gfA is a Galois field array, you can not apply dex2hex directly.
But gfA.x returns corresponding numeric array, so please try dec2hex(gfA.x) to obtain hexa values.
I got an error stating :
>> hash1
Undefined function or variable 'gf2dec'.
Error in hash1 (line 23)
gfAH= gf2dec(gff.x);
gff = gfA .* gfH;
What must be done??
can somebody help me to solve this error??
function DecOutput = gf2dec(GFInput)
GFInput=[172 106 200 187 68 251 103 2 149 131 25 55 237 110 129 231];
%GFInput = GFInput(:)';% force a row vector
GFRefArray = gf([0:(2^1)-1]);
for i=1:length(GFInput)
for k=0:(2^1)-1
temp = isequal(GFInput(i),GFRefArray(k+1));
if (temp==1)
DecOutput(i) = k;
end
end
end
This is the function, I got from the above example. Still i am getting an error.
Error in gf2dec (line 2)
GFInput=[172 106 200 187 68 251 103 2 149 131 25 55 237 110 129 231];
Output argument "DecOutput" (and maybe
others) not assigned during call to
"gf2dec".
Error in hash1 (line 24)
gfAH= gf2dec(gff.x);
Error in encrygc (line 84)
HA=hash1(g);
What might be the issue?
GFRefArray = gf([0:(2^1)-1]);
contains only 0 and 1 because that is what you asked for. It would need to be
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!