tjpc3 The Redstoner
tjpc3 The Redstoner

Reputation: 11

How can I work with numbers larger than 2^1024 in Lua

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?

Upvotes: 0

Views: 593

Answers (2)

warspyking
warspyking

Reputation: 3113

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.

Upvotes: 0

Ctx
Ctx

Reputation: 18410

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

Upvotes: 4

Related Questions