Jump to content

Need help converting from C++


wolves

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.