Bitwise operations and md4digest function

2005-11-23 Thread Alejandro Tejada
Hi all,

i've been porting this md4digest function
from Macromedia Director to Runtime Revolution:
http://www.isometrik.org/md5/lingo_md4_fastest.txt

Some differences i had noticed while handling
numbers are:

Numeric Arrays in Director starts from 0 (zero)
Numeric Arrays in Runrev starts from 1 (one)

In Director:
put (24 + 64) / 512 * 16 + 16
results in 16

In RunRev 
put (24 + 64) / 512 * 16 + 16
results in 18.75

To get the same result in RunRev
i had to rewrite the operation like this:
put round((24 + 64)/( 512 * 16)) + 16

More problematic is that bitwise operations
do not return the same results in
Director and Runrev... for example

in Director
put bitAnd(-271733879,-1732584194)
returns -2004318072 

in RunRev
put -271733879 bitand -1732584194
returns 0 (zero)

How could i get the same the result in RunRev as
this bitAnd operation made in Director?

Thanks in advance.

alejandro

Visit my site:
http://www.geocities.com/capellan2000/



__ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Bitwise operations and md4digest function

2005-11-23 Thread Alex Tweedly

Alejandro Tejada wrote:


Hi all,

i've been porting this md4digest function
from Macromedia Director to Runtime Revolution:
http://www.isometrik.org/md5/lingo_md4_fastest.txt

Some differences i had noticed while handling
numbers are:

Numeric Arrays in Director starts from 0 (zero)
Numeric Arrays in Runrev starts from 1 (one)

In Director:
put (24 + 64) / 512 * 16 + 16
results in 16

In RunRev 
put (24 + 64) / 512 * 16 + 16

results in 18.75

To get the same result in RunRev
i had to rewrite the operation like this:
put round((24 + 64)/( 512 * 16)) + 16

 


Right.
Director is using all integer arithmetic, so 88/512 gives 0, multiply by 
16 is still 0, and add 16 is 16.
Rev uses dynamic typing, so 88/512 gives some small fraction, multiply 
by 16 gives 2.75m and add 16 gives you the 18.75



More problematic is that bitwise operations
do not return the same results in
Director and Runrev... for example

in Director
put bitAnd(-271733879,-1732584194)
returns -2004318072 


in RunRev
put -271733879 bitand -1732584194
returns 0 (zero)

How could i get the same the result in RunRev as
this bitAnd operation made in Director?

 

The problem here is that Rev's bitand operator is defined to work for 
positive numbers only. From the docs:



Parameters:
The number1 and number2 are numbers, or expressions that evaluate to 
numbers, between zero and 4,294,967,295 (2^32 - 1).


Because your values are less than 0, it gives wrong answer - they 
appear to be  0 because the top bit is set - the original code probably 
had them defined as unsigned integers (which Director probably doesn't 
support). You can get the right result with



function mybitand p1, p2
  if p1  0 then  add 2^32 to p1
  if p2  0 then  add 2^32 to p2
  return p1 bitand p2
end mybitand


but you may be able to avoid the need for this depending on how the 
input values here are built-up. If they are the results of other bit 
operators, then in Rev it ought to be possible to keep everything as 
positive values, and then just use the standard bitand operator.


If the code isn't too long, I'd be happy to take a look 

--
Alex Tweedly   http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.4/176 - Release Date: 20/11/2005

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Bitwise operations and md4digest function

2005-11-23 Thread Sean Shao
Alejandro, if you are using Rev 2.5.x or lower, Rev can't do any math with 
numbers larger than 0xFFF (7 F's) Rev 2.6 and greater can (I don't know 
the limits as I only needed 0x (8 F's))  I'm having similiar 
problems with bit math and am looking at rolling my own..


_
Is your PC infected? Get a FREE online computer virus scan from McAfee® 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Bitwise operations and md4digest function

2005-11-23 Thread Alex Tweedly

Sean Shao wrote:

Alejandro, if you are using Rev 2.5.x or lower, Rev can't do any math 
with numbers larger than 0xFFF (7 F's) Rev 2.6 and greater can (I 
don't know the limits as I only needed 0x (8 F's))  I'm having 
similiar problems with bit math and am looking at rolling my own..



It can do some arithmetic above 0xFFF (7 Fs)

For instance, in 2.5 and 2.2.1 I can do

put format(%x, 2^31 + 5)    8005
(i.e. it has successfully taken an addition into the range above INT32)

or even
  put format(%08x %u, 2^32 / 2^30, 2^32 / 2^30)   ---  0004  4

I'd be interested to hear what things you had trouble with ...

--
Alex Tweedly   http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.4/176 - Release Date: 20/11/2005

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: Bitwise operations and md4digest function

2005-11-23 Thread Alex Tweedly

Alex Tweedly wrote:


It can do some arithmetic above 0xFFF (7 Fs)

For instance, in 2.5 and 2.2.1 I can do

put format(%x, 2^31 + 5)    8005
(i.e. it has successfully taken an addition into the range above INT32)

or even
  put format(%08x %u, 2^32 / 2^30, 2^32 / 2^30)   ---  0004  4

I'd be interested to hear what things you had trouble with ...


Not to worry - I found some that fail, so I'm now happy to not use it.
Haven't figured out the pattern yet - but have found enough to convince 
me it's not usable without great care - and possible not even *with* care.


--
Alex Tweedly   http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.4/176 - Release Date: 20/11/2005

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution