### tea algorithm

hi guys, i`m trying to figure out how to use these two methods of tea algorithm that i have gotten from wikipedia.

 ``12345678910111213141516171819202122232425`` ``````#include void encrypt (uint32_t* v, uint32_t* k) { uint32_t v0=v[0], v1=v[1], sum=0, i; /* set up */ uint32_t delta=0x9e3779b9; /* a key schedule constant */ uint32_t k0=k[0], k1=k[1], k2=k[2], k3=k[3]; /* cache key */ for (i=0; i < 32; i++) { /* basic cycle start */ sum += delta; v0 += ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + k1); v1 += ((v0<<4) + k2) ^ (v0 + sum) ^ ((v0>>5) + k3); } /* end cycle */ v[0]=v0; v[1]=v1; } void decrypt (uint32_t* v, uint32_t* k) { uint32_t v0=v[0], v1=v[1], sum=0xC6EF3720, i; /* set up */ uint32_t delta=0x9e3779b9; /* a key schedule constant */ uint32_t k0=k[0], k1=k[1], k2=k[2], k3=k[3]; /* cache key */ for (i=0; i<32; i++) { /* basic cycle start */ v1 -= ((v0<<4) + k2) ^ (v0 + sum) ^ ((v0>>5) + k3); v0 -= ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + k1); sum -= delta; } /* end cycle */ v[0]=v0; v[1]=v1; }``````

i have been trying to initialize a uint32_t variable to contain a string. However it says invalid conversion from char * to unint32_t. How do i pump variables into these two methods?
and how do i declare uint32_t variables?
i also want to know how to convert an int to uint32_t type!

 ``12`` ``````int x = 5; uint32_t y = x;``````

Compiler will issue warning about conversion between signed and unsigned types. Actually it is better to use uint32_t to store info related to encryption everywhere.
thanks man!
so i will do the same for string?

correct me if i`m wrong
uint32_t always converts variables to 32 bits?

and i`m having trouble in encrypting my data with the tea algorithm
i converted the string values to ascii values and stored them in a vector.
Then i called them out in another for loop to encrypt them, however i keep getting segmentation faults. May i know whats wrong with my code?

 ``123456789101112131415161718192021222324252627282930313233`` ``````int main() { string userInput; int getKey=0x95a8882c; uint32_t *TEAKey=(uint32_t *) getKey; vector storeAscii; cout<<"5-bit CFB TEA algorithm program"<>userInput; for(int i=0;i
Last edited on
Topic archived. No new replies allowed.