Jump to content

Archived

This topic is now archived and is closed to further replies.

wolves

Need help converting from C++

Recommended Posts

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

[code]
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;
}
[/code]

AnsiString is a string bigger than type String

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote author=king arthur link=topic=103609.msg412663#msg412663 date=1155153112]
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.
[/quote]

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.