Moram da uradim AES kriptografski algoritam u openCL-u, sa svim koracima i fazama radi paralelizacije. Na pocetku trebam da ulazni tekst pretvorim
u blokove od 128bita (odnoscno matricu 4x4 heksadecimalnih vrijednosti).
Ali je problem sto ne znam kako da napravim tu matricu da sadrzi heksadecimalne vrijednosti.
Ucitao sam ulazni tekst u niz znakova (char *) i kad ih ispisem, ispise ih kao slova.
char* readFile(const char* filename)
{
char* source;
long length;
FILE * f = fopen(filename, "r");
if (f)
{
fseek(f, 0, SEEK_END);
length = ftell(f);
fseek(f, 0, SEEK_SET);
source = (char*)calloc(length, sizeof(char));
if (source)
fread(source, 1, length, f);
fclose(f);
}
return source;
}
int main(int argc, char* argv[]){
char * ulaz= readFile("test.txt");
cout<<ulaz<<endl; //ispise normalan tekst kako je u txt falju
long length=fileLength("test.txt");
for(int i=0; i<length; i++)
{
cout <<hex << (int)ulaz[i]<<","; //ispisuje heksadecimalne vrijednosti koje trebam da stavim u blokove (matrice)
}
}
Ovo je ulazni tekst
Finding the best price for the Lenovo Vibe P2 64GB is no easy task. Here you will find where to buy the Lenovo Vibe P2 64GB at the best price.
Prices are continuously tracked in over 140 stores so that you can find a reputable dealer with the best price
Ovo je rezultat.
46,69,6e,64,69,6e,67,20,74,68,65,20,62,65,73,74,20,70,72,69,63,65,20,66,6f,72,20
,74,68,65,20,4c,65,6e,6f,76,6f,20,56,69,62,65,20,50,32,20,36,34,47,42,20,69,73,2
0,6e,6f,20,65,61,73,79,20,74,61,73,6b,2e,20,48,65,72,65,20,79,6f,75,20,77,69,6c,
6c,20,66,69,6e,64,20,77,68,65,72,65,20,74,6f,20,62,75,79,20,74,68,65,20,4c,65,6e
,6f,76,6f,20,56,69,62,65,20,50,32,20,36,34,47,42,20,61,74,20,74,68,65,20,62,65,7
3,74,20,70,72,69,63,65,2e,20,50,72,69,63,65,73,20,61,72,65,20,63,6f,6e,74,69,6e,
75,6f,75,73,6c,79,20,74,72,61,63,6b,65,64,20,69,6e,20,6f,76,65,72,20,31,34,30,20
,73,74,6f,72,65,73,20,73,6f,20,74,68,61,74,20,79,6f,75,20,63,61,6e,20,66,69,6e,6
4,20,61,20,72,65,70,75,74,61,62,6c,65,20,64,65,61,6c,65,72,20,77,69,74,68,20,74,
68,65,20,62,65,73,74,20,70,72,69,63,65,
Koju strukturu da napravim da bi to izgledalo ovako? I kako napraviti da bude bas blok (matrica) heksadecimalnih vrijednosti?? Jer kada ih ovako ispisujem
tretiraju se kao integeri od 4 bajta (32bita), a meni treba da to bude 1 bajt u heksadecimalnom obliku.
Mislio sam da napravim vector 2d nizova (tj matrica), ali ne znam koliko je to dobro i prakticno.
46,69,6e,64,
69,6e,67,20,
74,68,65,20,
62,65,73,74,
20,70,72,69,
63,65,20,66,
6f,72,20,74,
68,65,20,4c,
65,6e,6f,76,
6f,20,56,69,
62,65,20,50,
32,20,36,34,
47,42,20,69,
73,20,6e,6f,
20,65,61,73,
79,20,74,61,
..........