Jump to content


Photo

Need help converting from C++


  • Please log in to reply
2 replies to this topic

#1 wolves

wolves
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 09 August 2006 - 07:42 PM

I need help to convert this function from c++ to php

long MontaChave(AnsiString chave, long seed)
{
  union
    {
    long chave;
    unsigned char bytes[sizeof(long)];
    } Buffer,Old;

  Buffer.chave = seed;
  Old.chave = seed;

  if (chave == "")
    {
    throw EConvertError("Chave para codificação não pode estar vazia");
    }

  for(char *pos = chave.c_str(); *pos; pos++)
    {
    Buffer.bytes[0] ^= (unsigned char)~*pos;
    Buffer.bytes[1] ^= (unsigned char)~*pos;
    Buffer.bytes[2] ^= (unsigned char)~*pos;
    Buffer.bytes[3] ^= (unsigned char)~*pos;
    }
  if(!Buffer.bytes[0]) Buffer.bytes[0] = Old.bytes[0];
  if(!Buffer.bytes[1]) Buffer.bytes[1] = Old.bytes[1];
  if(!Buffer.bytes[2]) Buffer.bytes[2] = Old.bytes[2];
  if(!Buffer.bytes[3]) Buffer.bytes[3] = Old.bytes[3];

  return Buffer.chave;
}

AnsiString is a string bigger than type String

#2 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 09 August 2006 - 07:51 PM

First, you might want to edit your post and remove the swearing before a moderator does it for you.

Second, you're going to need to find a way to overcome PHP's lack of unions and pointers to convert this code. Also find out what type AnsiString is.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#3 wolves

wolves
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 09 August 2006 - 08:00 PM

First, you might want to edit your post and remove the swearing before a moderator does it for you.

Second, you're going to need to find a way to overcome PHP's lack of unions and pointers to convert this code. Also find out what type AnsiString is.


sorry my english is bad and I don't know the meaning of """remove the swearing"""" ?

pointers? u mean &$myvar?

and AnsiString  is a string bigger then type String

tks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users