Here's a small PRNG called fliptag. It uses mostly linear math and its state can be completely kept within only 6 "registers" and the implementation is only 27 lines of code long.
I ran ent, DIEHARD and the NIST.GOV test suite against it (though I only did all the tests for one fixed seed). I re-ran ent with this, because this implementation has a system-time dependent seed.
fliptag has 4 seed parameters, of which 3 are optional. The first one is the genesis seed and determines the starting state. Because this seed is very sensitive to small decimal changes, the current system tickcount (modified) is used in addition to the current system time. (AutoIts MT uses time(NULL))
Here are some sample ent results from the AutoIt test suite, which generates a 1,5 MB file from random bytes:
A truly random sequence has an entropy value of 8.0. This is however not achievable by any software PRNG. Both PRNG are on par and have a very respectable entropy value.
A dense file (with high entropy) cannot be compressed. Both PRNG achieve perfect scores.
The chi-square test is the most commonly used test for the randomness of data, and is extremely sensitive to errors in pseudorandom sequence generators. The chi-square distribution is calculated for the stream of bytes in the file and expressed as an absolute number and a percentage which indicates how frequently a truly random sequence would exceed the value calculated. We interpret the percentage as the degree to which the sequence tested is suspected of being non-random. If the percentage is greater than 99% or less than 1%, the sequence is almost certainly not random. If the percentage is between 99% and 95% or between 1% and 5%, the sequence is suspect. Percentages between 90% and 95% and 5% and 10% indicate the sequence is “almost suspect”.
Both PRNGs achieve very good results. For comparison, Unix' rand() achieves a catastrophic 0.01, a Park & Miller PRNG will achieve roughly 97.5, while a truly - physical - random sequence will result in a Chi² score of about 40.9.
4. Arithmetic mean value
Truly random sequences have an arithmetic mean value of exactly 127.5 (0xFF * 0.5). Both PRNG achieve near-perfect scores.
5. Monte Carlo Pi
Each successive sequence of six bytes is used as 24 bit X and Y co-ordinates within a square. If the distance of the randomly-generated point is less than the radius of a circle inscribed within the square, the six-byte sequence is considered a “hit”. The percentage of hits can be used to calculate the value of Pi. For very large streams (this approximation converges very slowly), the value will approach the correct value of Pi if the sequence is close to random.
Considering that even radioactive decay (true physical randomness) will not achieve better results than both PRNGs. So the scores are almost perfect.
6. Serial Correlation
This quantity measures the extent to which each byte in the file depends upon the previous byte. For random sequences, this value (which can be positive or negative) will, of course, be close to zero. A non-random byte stream such as a C program will yield a serial correlation coefficient on the order of 0.5. Wildly predictable data such as uncompressed bitmaps will exhibit serial correlation coefficients approaching 1.
Both PRNGs achieve very good results.
The StringToByte function , I expected to return 0s and 1s as strings displayed, but in fact it returns in hex if Im not wrong like 0xH3J4H....
How can I make to return to me the expression of a string in bits ?
I'm having trouble with rounding. The program I'm using rounds decimals down. Autoit's round function rounds them up.
round(174.126, 2) = 174.13
I need that round to be 174.12.
Here's the actually script:
#Region ### START Koda GUI section ### Form=C:Program FilesAutoinstallForm1.kxf
$Form1 = GUICreate("AutoCalc", 227, 200, 15, 15, $WS_EX_TOPMOST)
$Button1 = GUICtrlCreateButton("Calculate", 8, 144, 99, 25)
$Button2 = GUICtrlCreateButton("Close", 120, 144, 91, 25)
$Label4 = GUICtrlCreateLabel("", 72, 136, 4, 4)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Group1 = GUICtrlCreateGroup("Input", 8, 8, 209, 129)
$Label1 = GUICtrlCreateLabel("Rate", 16, 32, 27, 17)
$Label2 = GUICtrlCreateLabel("Number of Nights", 16, 64, 86, 17)
$Input1 = GUICtrlCreateInput("0.00", 112, 24, 89, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_RIGHT))
$Label3 = GUICtrlCreateLabel("Total", 16, 96, 45, 28)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("1", 112, 56, 89, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_RIGHT))
;$Label5 = GUICtrlCreateLabel("0.00", 136, 96, 39, 28)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
#EndRegion ### END Koda GUI section ###
$nMsg = GUIGetMsg()
;$val = round((((((GUICtrlRead($input1) * .1545) + GUICtrlRead($input1)) + 1.5 + .13) * GUICtrlRead($input2))), 2)
$val = (((((GUICtrlRead($input1) * .1545) + GUICtrlRead($input1)) + 1.5 + .13) * GUICtrlRead($input2)))
$Label5 = GUICtrlCreateLabel($val, 136, 96, 39, 28)
Hi all, I need to generate an HMAC hash using SHA512 according to a certain API's specs and the only HMAC example I've seen () does not work as I need it do, even adapting it from a 64-bit blocksize to 512 and adding Ward's_SHA512 UDF.
I've tried the following:
Func _HashHMAC512($key, $message) $key = _StringRepeat("0", 512 - StringLen($key)) & $key ; keys shorter than blocksize are zero-padded ('?' is concatenation) $o_key_pad = BitXOR(0x5c * 512, $key) ; Where blocksize is that of the underlying hash function $i_key_pad = BitXOR(0x36 * 512, $key) ; Where ? is exclusive or (XOR) Return _SHA512($o_key_pad & _SHA512($i_key_pad & $message)) EndFunc
But, of course, it doesn't work (I suspect I'm doing something very blatantly wrong, but as I lack fundamental understanding about binary and hex number formats I can't see what's the issue right off the top of my head.)
Note: in my case $key will always by 68 characters long so it will always prepend the leading zeroes.
As a litmus test, I need to hash the message 1239348906120181 with the key ba63a816f030cefeea4803cd593569ce23f3815d0cc8c56d9194df6226dca2f0f48239698bc68991cfac387449b07b0f722f6f3df761dbc1fe8894dd65ff00b2 and receive 2610740031eeab61bbe6cd3f08daa6186ff0d59f5ec045dbb0e194fea8998b4f3d1da9aae0f718f8c126d6418302e081d68a82f0576eb266b68f26dc3459b62f as the output.
I've been working on this for the past 4-odd hours now, to no avail. I really, really don't want to have to restart my project in python or php or somesuch... or, for that matter, write the hash function in js, python, or php and somehow bootleg that single function's results into my au3 project. I would greatly appreciate any help from ye wise ents, even if it's just a nudge in the right direction.
I'm wondering how to make a zero-fill right shift in autoit as far as the BitShift function has no parameter for this.
Thanks for anyhelp,