Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

big number math


  • Please log in to reply
10 replies to this topic
nate11000
  • Guests
  • Last active:
  • Joined: --
I'm trying to create an RSA-like 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!

slomz
  • Members
  • 601 posts
  • Last active: Mar 30 2008 12:54 AM
  • Joined: 03 Sep 2006
Did you use that in an expression?
Posted Image

nate11000
  • Members
  • 4 posts
  • Last active: Sep 29 2008 05:22 AM
  • Joined: 03 Dec 2006
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.

slomz
  • Members
  • 601 posts
  • Last active: Mar 30 2008 12:54 AM
  • Joined: 03 Sep 2006
what is the largest number?
Posted Image

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012

what is the largest number?

Variable Capacity and Memory

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


slomz
  • Members
  • 601 posts
  • Last active: Mar 30 2008 12:54 AM
  • Joined: 03 Sep 2006
I mean what is the largest number that he is using. I know what AHK can take
Posted Image

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
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.

nate11000
  • Members
  • 4 posts
  • Last active: Sep 29 2008 05:22 AM
  • Joined: 03 Dec 2006
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.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
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


Lemming
  • Members
  • 184 posts
  • Last active: Feb 03 2014 11:03 AM
  • Joined: 20 Dec 2005
Sounds like he's doing Diffie-Hellman key exchange. This requires a minimum of 512-bit numbers, according to security standards. Ahk can only handle maximum of 64-bit integers.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

Ahk can only handle maximum of 64-bit integers.

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 *.