GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Mar-2005, 21:08
Tiza Naziri Tiza Naziri is offline
New Member
 
Join Date: Mar 2005
Posts: 3
Tiza Naziri is on a distinguished road

polynomial extended euclidean algorithm


Hi,

I need some advice & suggestions on how to represent the finite field GF(2^ operations (such as addition, inversion, multiplication) in binary representation in C language. Another thing is how to represent the pseudocode for generating multiplicative inverse below:

remainder[1] = f(x)
remainder[2] = a(x)
auxiliary[1] = 0
auxiliary[2] = 1

i = 2

do while remainder[i] <> 1
i = i + 1
remainder[i] = remainder(remainder[i-2] / remainder[i-1])
quotient[i] = quotient(remainder[i-2] / remainder[i-1])
auxiliary[i] = quotient[i] * auxiliary[i-1] + auxiliary[i-2]
inverse = auxiliary[i]

For AES, the f(x) = x^8 + x^4 + x^3 + x + 1.

Thank you & Regards.

-- Tiza --
  #2  
Old 15-Mar-2005, 00:59
Tiza Naziri Tiza Naziri is offline
New Member
 
Join Date: Mar 2005
Posts: 3
Tiza Naziri is on a distinguished road

polynomial extended Euclidean algorithm


Hi,

Anybody have an idea on how to start writing a C code for generating
the inverse of finite field GF(2^8 ) using extended Euclidean algorithm?
What I mean is how to represent a polynomial, e.g. f(x)=x^8+x^4+x^3+x+1
in C? How to represent the multiplication & division process of
polynomial?

Regards.

-- Tiza --
Last edited by Tiza Naziri : 15-Mar-2005 at 01:02. Reason: unwanted 'smiley' appears
  #3  
Old 15-Mar-2005, 09:00
QED's Avatar
QED QED is offline
Member
 
Join Date: Feb 2005
Location: Hudson Valley, NY
Posts: 231
QED is a jewel in the roughQED is a jewel in the roughQED is a jewel in the rough
For future reference, the moderators generally frown upon posting more than one thread with the same question. Sometimes it takes a little while for someone who is knowledgeable about your question to see the thread, have time to respond, and work up a response. Be patient, then maybe reply to your own thread to bring it to the top of the list again if you want to draw more attention to it.

As for your question, the answer is: you can represent a polynomial in whatever way you can think of. There is usually not a single correct answer when it comes to questions of how to design something.

I'll offer a specific example of how I might approach this, but you should decide what is right for you and your application, and whether or not there might be a better approach.

First I would start by asking what defines a polynomial; that is, what makes it what it is. Well, the coefficient and the exponents pretty much capture everything you need to know. The highest exponent is typically given special significance, and called the degree, or order, of the polynomial.

One idea is to use an array to store the coefficients and let the array index represent the exponent of the term to which that coefficient applies. Note that for this we have to include zeros (0) for the terms that do not appear, up to the polynomial's degree. The size of the array will be the degrre of the polynomial plus 1. For your sample polynomial (writing it backwards so we can see more easily how is translates to an array), we use
(1 * x^0) + (1 * x^1) + (0 * x^2) + (1 * x^3) + (1 * x^4) + (0 * x^5) + (0 * x^6) + (0 * x^7) + (1 * x^8 )
So, the array contains (with the index listed above the element)
CPP / C++ / C Code:
// Array index:       0    1    2    3    4    5    6    7    8
float coeffs[8+1] = { 1,   1,   0,   1,   1,   0,   0,   0,   1 };

It might seem like a waste of space to store the zero coefficients, especially for high order polynomials with only a few non-zero terms. But the extra storage is very minimal (who is going to be dealing with polynomials of degree 1000?). Any approach that tries to store only what is needed will almost certainly have MORE overhead rather than less for typical polynomials.

Now, the arithmetic operations become pretty straightforward, since you can just move through the array picking up the exponent and coefficient for each term of the polynomials.

In C++, I would use an object-oriented design, with a class that represents the polynomials and probably using operator overloading to implement the arithmetic operations.

If working in C only, I would just implement functions for the arithmetic operations that take as arguments the degree and the array of coefficients for each polynomial. Maybe a prototype would look like this:
CPP / C++ / C Code:
void addPolynomials(float  *coeffs1,   // pointer to 1st coefficient array
                    int     degree1,   // size of 1st array minus 1
                    float  *coeffs2,   // pointer to 2nd coefficient array
                    int     degree2,   // size of 2nd array minus 1
                    float **coeffs3,   // pointer to pointer to sum array
                    int    *degree3);  // size of new (3rd) array minus 1
Note that the last two parameters are for returning the new polynomial. You could also pass the size of the array itself (degree plus 1) rather than the degree, and make the appropriate adjustments to the function body.

However, I would choose C++ rather than C, if there is a choice.

If you can and want to use C++ instead, I would be willing to share some code ideas for that as well.

Matthew


* EDITED for typos *
  #4  
Old 15-Mar-2005, 21:14
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by QED
For future reference, the moderators generally frown upon posting more than one thread with the same question. Sometimes it takes a little while for someone who is knowledgeable about your question to see the thread, have time to respond, and work up a response. Be patient, then maybe reply to your own thread to bring it to the top of the list again if you want to draw more attention to it.
No, bumping your thread is also frowned upon.
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
  #5  
Old 16-Mar-2005, 01:48
Tiza Naziri Tiza Naziri is offline
New Member
 
Join Date: Mar 2005
Posts: 3
Tiza Naziri is on a distinguished road
Quote:
Originally Posted by WaltP
No, bumping your thread is also frowned upon.

Sorry, actually I have been putting the same thread title because I thought that the previous question / thread is not really focussed to what I really need.
  #6  
Old 16-Mar-2005, 07:32
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Tiza Naziri
Sorry, actually I have been putting the same thread title because I thought that the previous question / thread is not really focussed to what I really need.
All you need to do is focus the question then. Posts are read no matter how deep they are.
__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
  #7  
Old 16-Mar-2005, 08:37
QED's Avatar
QED QED is offline
Member
 
Join Date: Feb 2005
Location: Hudson Valley, NY
Posts: 231
QED is a jewel in the roughQED is a jewel in the roughQED is a jewel in the rough
Quote:
Originally Posted by WaltP
No, bumping your thread is also frowned upon.
Sorry if I unintentionally promoted a behavior that is not acceptable.

Matthew
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help.... SLR * algorithm tay C Programming Language 4 10-Sep-2004 11:48

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:41.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.