TEA Encrypt To PB

Windows specific forum
j50501313
User
User
Posts: 20
Joined: Fri Oct 23, 2009 11:51 am

TEA Encrypt To PB

Post 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.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: TEA Encrypt To PB

Post by Rings »

so in detail , what is your problem with the code,
what did you not understand ?
SPAMINATOR NR.1
X
Enthusiast
Enthusiast
Posts: 311
Joined: Tue Apr 04, 2006 6:27 am

Re: TEA Encrypt To PB

Post by X »

From what I read in his post, he stumbled across a piece of code he wants converted to PB.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: TEA Encrypt To PB

Post 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
BERESHEIT
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: TEA Encrypt To PB

Post by blueb »

:lol:

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

--Bob
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: TEA Encrypt To PB

Post 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
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Post Reply