I'm trying to create an RSAlike security function, but I need to be able to do math with huge exponents. I don't know exactly how large AHK allows numbers to be, but I can't get past somewhere in the neighborhood of 2^63 before it starts acting wacky.
Is there any way to do that in AHK? When I was searching for an answer, I found a reference to a script that had implemented RSA with 1024 bit keys, which would be plenty, but the link to the actual script was dead.
Thanks for your help!
big number math
Started by
nate11000
, Dec 03 2006 12:14 AM
10 replies to this topic
#1

Posted 03 December 2006  12:14 AM
I assume you're talking about the 2^63 figure... No. I fiddled with it for a bit to see how high it would go, but it's an approximation, in any case. The figures I need to actually use are much, much larger than that. Also, I'm pretty sure that in other languages there are separate math functions to accomodate large calculations like these.
#3

Posted 03 December 2006  04:33 AM
I mean what is the largest number that he is using. I know what AHK can take
#6

Posted 03 December 2006  04:30 PM
512 bit encryption necessarily requires the ability to do math on numbers as large as 2^512, which is astronomical.
Your best bet is to find a cli program that can calculate big numbers, I think. If you have access to a copy of MATLAB with a compiler, you could have MATLAB do the math in a small compiled function.
Your best bet is to find a cli program that can calculate big numbers, I think. If you have access to a copy of MATLAB with a compiler, you could have MATLAB do the math in a small compiled function.
#7

Posted 03 December 2006  04:34 PM
Well, as I said before, many languages have separate functions and objects for math that big. I was hoping somebody had done it before to avoid the slowness of using multiple programs, but I suppose I"ll make something separate. Thanks.
#8

Posted 03 December 2006  05:52 PM
I don't think anyone posted the necessary modular arithmetic functions, written in AHK. Although it was not hard (using strings of hex digits for representing integers), the performance is likely to be terrible. It looks easier to have a complete long integer function library compiled to a dll and call these functions via dllcalls. GMP is free and one of the fastest. There are also programs (e.g. Landon Noll's calc), which take simple long integer expressions and return them evaluated. It is easier to use and almost as fast. I use the following script to append the result to a selected math expression in any editor, at pressing the hotkey Win=:
#=:: ; Append arbitrary precision calculation result ClipBoard = Send ^x ; Cut  Reinsert (caret can be in either end of selection) ClipWait 1 If ErrorLevel { Send {End}+{Home} Send ^x ClipWait 1 } StringRight last, ClipBoard, 1 ; Remove trailing new line IfEqual last,`n, StringTrimRight ClipBoard,ClipBoard,1 StringRight last, ClipBoard, 1 IfEqual last,`r, StringTrimRight ClipBoard,ClipBoard,1 StringReplace calc,ClipBoard,^, ^^, All StringReplace calc, calc, <, ^<, All StringReplace calc, calc, >, ^>, All RunWait %Comspec% /c "%A_ProgramFiles%\GnuWin32\bin\calc.exe" p %calc% > c:\calc.tmp,,HIDE FileRead Result, c:\calc.tmp StringTrimRight Result, Result, 2 StringReplace Result, Result, `r`n, `;, All Send ^v = %Result% Return
#9

Posted 04 December 2006  04:22 AM
Sounds like he's doing DiffieHellman key exchange. This requires a minimum of 512bit numbers, according to security standards. Ahk can only handle maximum of 64bit integers.
#10

Posted 09 December 2006  02:41 PM
You can easily write long integer arithmetic functions in AHK. Numbers are represented by strings of their digits, and you have to use your functions for arithmetic, not the built in operators, like + or *.Ahk can only handle maximum of 64bit integers.
#11

Posted 09 December 2006  02:55 PM