Page 1 of 1

TEA Encrypt To PB

Posted: Tue Nov 17, 2009 9:08 am
by j50501313
Hello, I'm j50501313 and I'm new to PureBasic. While I really enjoy what I see so far,
I stumbled across this piece of C code that I'd like to convert to PB.

Code: Select all

#include <winsock.h>
#define ROUNDS 16
#define DELTA 0x9e3779b9 

void Encrypt(long* v, long* k, long* out);
void Decrypt(long* v, long* k, long* out);

int main(int argc, char* argv[])
{
  long v[2], k[4], out[2];
  v[0]=0x97849FC5;
 v[1]=0xC663ADEA;

 k[0]=0x3A9DAA0A;
  k[1]=0xCE16881A;
  k[2]=0xFD045661;
  k[3]=0xBCF5C5D4;

  QQEncrypt(v,k,out);
  QQDecrypt(out,k,out);
  return 0;
}

void Encrypt(long* v, long* k, long* out)
{
unsigned long y=v[0],z=v[1],x[4],sum=0;
long limit=ROUNDS;
long test1;

y=ntohl(y);
z=ntohl(z);

for (int i=0;i<4;i++)
  x[i]= ntohl(k[i]);
while (limit-->0)
{
  sum += DELTA ;
  test1=(z>>5);
  y += (z<<4)+x[0] ^ z+sum ^ (z>>5)+x[1] ;
  z += (y<<4)+x[2] ^ y+sum ^ (y>>5)+x[3] ; 
}
out[0]=ntohl(y) ;
out[1]=ntohl(z) ;
}

void Decrypt(long* v, long* k, long* out)
{
unsigned long y=v[0],z=v[1],x[4],sum=0xe3779b90; 
long limit=ROUNDS;

y=ntohl(y);
z=ntohl(z);

for (int i=0;i<4;i++)
  x[i]= ntohl(k[i]);
while (limit-->0)
{
  z -= (y<<4)+x[2] ^ y+sum ^ (y>>5)+x[3] ;
  y -= (z<<4)+x[0] ^ z+sum ^ (z>>5)+x[1] ; 
  sum -= DELTA ;
}
out[0]=ntohl(y) ;
out[1]=ntohl(z) ;
}

I wonder if someone could please help me out. Thank you in advance.

Re: TEA Encrypt To PB

Posted: Tue Nov 17, 2009 9:14 am
by Rings
so in detail , what is your problem with the code,
what did you not understand ?

Re: TEA Encrypt To PB

Posted: Sat Nov 28, 2009 1:13 am
by X
From what I read in his post, he stumbled across a piece of code he wants converted to PB.

Re: TEA Encrypt To PB

Posted: Sat Nov 28, 2009 4:33 am
by netmaestro
Hello, I'm j50501313 and I'm new to PureBasic
Hello, I'm netmaestro and I wasn't born yesterday. Tell me how much you're willing to pay and I'll let you know if I'm interested in doing this for you.

All the best,

Lloyd

Re: TEA Encrypt To PB

Posted: Sat Nov 28, 2009 3:25 pm
by blueb
:lol:

LLoyd, you're funnier than a bullfrog with teeth.

--Bob

Re: TEA Encrypt To PB

Posted: Sat Nov 28, 2009 3:33 pm
by blueb
j50501313,

Here's another Basic site (powerbasic) that contains many algorithms, all gathered by Wayne Diamond, who sometimes drops into our forums.

You'll find a TEA algo on the list.

http://www.pbcrypto.com/pbcrypto.php


--blueb