dilluns, 16 de juliol del 2007

Reading vectors from a file & representing a code

Here is an example of how to use NTL library. This is a function I have used to read codes. I use the following format to save and load the code, I have tried to save the minium parameters necesaries to respresent code as standard way.

- int base of the code
- int word length
- int cardinal of the code (number of words)
- 1 line for each vector. form --> ( int int int int int )

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Reading Code from file
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
vec_ZZ_p io_read(list &code)
{
FILE *f;//File to read From
int i,j;
char c;
if (( f = fopen(filepath, "r+")) == NULL )
{
perror("This file can not be opened\n");
}

fscanf(f, "%d\n",&base);

/////////////// Definition used for the list of vectors ///////////////////
ZZ p; //Modulus of the vector
p = base;
ZZ_p::init(p); //Ring/Field definition
vec_ZZ_p v; //vector used to compute Intersection Array over ZZ_p
///////////////////////////////////////////////////////////////////////////////////////////

fscanf(f, "%d\n",&wordlength);
fscanf(f, "%d\n",&codecardinal);

v.SetLength(wordlength);

for (i = 0;i < codecardinal;i++)
{
for (j = 0;j < wordlength;j++)
{
fseek(f,1,SEEK_CUR);// jump the blckspace and the "(" character
c = fgetc(f); // get the character we want
v[j] = c-ASCII_CONVERSION;
}
fseek(f,2,SEEK_CUR);// jump the last chars of the string
code.push_back(v);
}
fclose(f);
return v;
}

dissabte, 7 de juliol del 2007

NTL: A Library for doing Number Theory

NTL is a very interesting free software library for C++ developers who are working on number theory. It provides a hight variety of structures like vectors and matrices thought to be used with big integers, floating point numbers and module mathematics.
It is very powerful, using the best algorithms known at the moment to do fast internal operations, transparents to programmers so it makes it easy to use.
As all "general function software" you can think that you can do it better, while you're doing more specific operations or just using a little part of these functions. In fact, there is always a time/optimization relationship and I really think that it's fast enought to be used with all kind of problems that involves these structures.
I haven't used all the fuctionalities given by this library. At the moment I have tried just module numbers and module numbers vectors, and i have to say that it works really fine. So I have decided to beguin all my programs using NTL, I will write in the future my advances with this library and the problems that I'll see.
At the moment, I am using it to represent codewords of codes over finite fields and over rings.
The worst thing is, that it is compiled using C++ language, so you can use it with C code but you will have to use a C++ compiler; I think it is easier to use C++ for all the code, you'll have the same functionalities of C and easier use, in fact you will lose some time because of the higher-level language that C++ represent.
I'll write an example to use it when I'll explain the C++ aplication I am working on.

You can find information, examples and download the library in http://shoup.net/ntl/

divendres, 6 de juliol del 2007

Hello everybody

I have decided to create a blog of programming, here you will find algorithms&code from those aplications i'm developing. The idea is to share with the comunity my interests and my work to discusse posible solutions of programming problems. At the moment my principals lines of work are based on coding theory and cryptology.
Someone said "if I have an idea and you have another one, if we share, we will have two ideas"