0

I'm trying to replicate some encryption methods in Lua and Lua doesn't like big numbers. For example:

print(6219^3445)
> inf

Does anybody know a way around this?

  • It's not a good idea to roll your own crypto, especially if this is a system for use in production. Find some Lua-C bindings for a tried-and-true library. – Colonel Thirty Two Dec 07 '15 at 00:30
  • See http://stackoverflow.com/questions/288707/what-is-the-standard-or-best-supported-big-number-arbitrary-precision-librar, one of the first Lua questions here. – lhf Dec 07 '15 at 01:33

2 Answers2

4

You could use a Lua-Library like: http://oss.digirati.com.br/luabignum/

For encryption, you might want to have a look at the openssl-bindings for lua, perhaps these already contain what you are trying to implement: http://luacrypto.luaforge.net/ or https://github.com/zhaozg/lua-openssl

Colonel Thirty Two
  • 23,953
  • 8
  • 45
  • 85
Ctx
  • 18,090
  • 24
  • 36
  • 51
  • I'm sorry I forgot to add this but with the circumstances I'm in I can't really use a library. It's not executing in the regular Lua interpreter. – tjpc3 The Redstoner Dec 07 '15 at 01:04
  • @tjpc3TheRedstoner That's OK for testing, or maybe some experiments. But in production it's a big no-no. – roeland Dec 07 '15 at 01:12
  • It's not for production. I guess I'll have to tell what I'm using it for. I'm trying to replicate RSA encryption (among other things) in Minecraft using OpenComputers (A computer mod) in lua. – tjpc3 The Redstoner Dec 07 '15 at 01:15
  • "For those who are familiar with LUA structures" (bignum) I turned around and never looked back once I read 'LUA' – warspyking Dec 07 '15 at 03:04
0

Well. A really stupid (but effective) way could be to hold your numbers in strings, and in math operations deal with each digit separately. Concatenate for tostring.

warspyking
  • 3,045
  • 4
  • 20
  • 37