Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Version of this?

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi. I'm trying to make a ClickBank validation script in PHP. The only problem is, that they only provide it for C and Perl. I know C is much like PHP, so I was wondering if anyone would possibly be able to translate it for me?

The C code is;

Code:
int valid(char *arg_seed, char *arg_cbpop, char *secret_key)
 // - Pass seed, cbpop, and your key as strings.
 // - Function returns 0 or 1.
 {
    // Copyright Keynetics Inc. Patents pending.
    char a[100], w[100], q[9];
    char *charsmask = "0123456789BCDEFGHJKLMNPQRSTVWXYZ";
    char *p;
    unsigned long int h, l, i, wi, x, y, z, n, s[10];
 
    if (!strcmp(arg_seed, ""))  { return 0; }
    if (!strcmp(arg_cbpop, "")) { return 0; }
 
    h=0x80000000; l=0x7fffffff; strcpy(q, "");
    sprintf(w,"%s %s",secret_key,arg_seed);
 
    p=w; while(*p){*p=toupper(*p);p++;}
    x=y=z=17; n=strlen(w);
 
    for(i=0;i<10;i++){s[i]=0;}
 
    for(i=0;i<256;i++)
      { wi=((x&l)+(y&l))^((x^y)&h);
        wi=(wi<<z)|(wi>>(32-z));
        wi=((wi&l)+w[i%n])^(wi&h);
        s[i&7]+=wi&31;
        z=y&31; y=x; x=wi;
      }
 
    for (i=0; i < 8; i++) { q[i] = charsmask[s[i] & 31]; }
    q[8] = '\0';
 
    if (!strcmp(arg_cbpop, q)) { return 1; }
    else { return 0; }
 }


Thanks :)

Andy
 
Try this:

<?
function valid($arg_seed, $arg_cbpop, $secret_key)
// - Pass seed, cbpop, and your key as strings.
// - Function returns 0 or 1.
{
// Copyright Keynetics Inc. Patents pending.
$charsmask = &quot;0123456789BCDEFGHJKLMNPQRSTVWXYZ&quot;;

if ($arg_seed!=&quot;&quot;) { return 0; }
if ($arg_cbpop!=&quot;&quot;) { return 0; }

$h=0x80000000; $l=0x7fffffff; $q=&quot;&quot;;
$w=sprintf(&quot;%s %s&quot;,$secret_key,$arg_seed);

$p=$w;
$p=strtoupper($p);
$x=$y=$z=17; $n=strlen($w);

for($i=0;$i<10;$i++){$s[$i]=0;}

for($i=0;$i<256;$i++)
{ $wi=(($x&l)+($y&l))^(($x^$y)&$h);
$wi=($wi<<$z)|($wi>>(32-$z));
$wi=(($wi&l)+$w[$i%$n])^($wi&$h);
$s[$i&7]+=$wi&31;
$z=$y&31; $y=$x; $x=$wi;
}

for ($i=0; $i < 8; $i++) { $q[$i] = $charsmask[$s[$i] & 31]; }
$q[8] = '\0';

if ($arg_cbpop!= $q) { return 1; }
else { return 0; }
}
?>

Is everything the same, only changed the vars to $var and one or two pieces of code i replaced by the function.
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top