Current location: Hot Scripts Forums » Programming Languages » C/C++ » Porting from PHP to C++


Porting from PHP to C++

Reply
  #1 (permalink)  
Old 09-07-04, 07:43 PM
whizmail whizmail is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Porting from PHP to C++

Hey guys... I have a PHP class that i'd need to use in a C++ software. Anyone could help me out?

<?php

// Class Made By Mukul Sabharwal [mukulsabharwal@yahoo.com]
// http://www.devhome.net/php/
// On October 21, 2000
// Updated February 24, 2001
// Now passes RC4 Vector Harness
class rc4crypt {
function endecrypt ($pwd, $data, $case='en') {
if ($case == 'de') {
$data = urldecode($data);
}
$key[] = "";
$box[] = "";
$temp_swap = "";
$pwd_length = 0;
$pwd_length = strlen($pwd);
for ($i = 0; $i <= 255; $i++) {
$key[$i] = ord(substr($pwd, ($i % $pwd_length), 1));
$box[$i] = $i;
}
$x = 0;
for ($i = 0; $i <= 255; $i++) {
$x = ($x + $box[$i] + $key[$i]) % 256;
$temp_swap = $box[$i];
$box[$i] = $box[$x];
$box[$x] = $temp_swap;
}
$temp = "";
$k = "";
$cipherby = "";
$cipher = "";
$a = 0;
$j = 0;
for ($i = 0; $i < strlen($data); $i++) {
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
$temp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $temp;
$k = $box[(($box[$a] + $box[$j]) % 256)];
$cipherby = ord(substr($data, $i, 1)) ^ $k;
$cipher .= chr($cipherby);
}
if ($case == 'de') {
$cipher = urldecode(urlencode($cipher));
} else {
$cipher = urlencode($cipher);
}
return $cipher;
}
}
?>

Thanks in advance!

Raphael Pirker
Reply With Quote
  #2 (permalink)  
Old 10-25-04, 12:52 PM
vek vek is offline
Newbie Coder
 
Join Date: Oct 2004
Location: Florence, Ky
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
I have been working on moving some of the php functions to c for me to use in cgi, so here are some that might help you.
Code:
int substr(char* str, char* substr, int offset, int length)
{
   int s_length = strlen(str);

   if ((str != NULL) && (length > 0))
   {
      if (offset >= 0)
      {
         if ((length - offset) >= s_length)
         {
            length = s_length - offset;
         }
      }
      else
      {
         if ((length - (s_length + offset)) >= (s_length + offset))
         {
            length = s_length - (s_length + offset);
         }
         offset = s_length + offset;
      }
      if ((offset >= 0) && ((s_length - 1) >= offset) &&
          (s_length >= (offset + length)))
      {
         strncpy(substr, str + offset, length);
         substr[length] = '\0';
         return(TRUE);
      }
      else if ((offset < 0) && (s_length >= (offset * -1)) &&
               (s_length >= ((s_length + offset) + length)))
      {
         strncpy(substr, str + (s_length + offset), length);
         substr[length] = '\0';
         return(TRUE);
      }
   }
   else if ((str != NULL) && (length < 0))
   {
      if (offset < 0)
      {
         offset = s_length + offset;
      }
      if ((offset >= 0) && ((s_length - 1) >= offset) &&
          (s_length > (length * -1)) &&
          ((s_length + length) > offset) &&
          (s_length >= ((s_length + length) - offset)))
      {
         strncpy(substr, str + offset, ((s_length + length) - offset));
         substr[((s_length + length) - offset)] = '\0';
         return(TRUE);
      }
   }

   substr[0] = '\0';
   return(FALSE);
}

int substr_compare(char* str1, char* str2, int offset, int length)
{
   char *substr;
   int ret;

   substr = (strlen(str1) > strlen(str2)) ? ((char *)calloc(strlen(str1) + 1, sizeof(char))) : ((char *)calloc(strlen(str2) + 1, sizeof(char)));

   substr(str1, substr, offset, length);

   ret = strcmp(substr, str2);

   free(substr);

   return(ret);
}

char chr(int ascii)
{
   return((char)ascii);
}

int ord(char chr)
{
   return((int)chr);
}
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
php with Apache in windows eDevil PHP 3 08-08-04 12:03 AM
PHP Dudes - Hi All stuart New Members & Introductions 4 05-03-04 01:22 PM
100 Web Templates & 10 PHP Scripts for sale! HostersUK.co.uk General Advertisements 0 01-10-04 12:31 AM
Realtime PHP Code Obfuscation barrywien General Advertisements 1 11-16-03 06:50 PM


All times are GMT -5. The time now is 04:33 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.