String arithmetic!
Language: lua
local chars = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"}
function add(a,b,base)
base = base or 10
local ret = ""
while a:sub(1,1)==chars[1] and #a>1 do a=a:sub(2) end
while b:sub(1,1)==chars[1] and #b>1 do b=b:sub(2) end
while #a<#b do a=chars[1]..a end
while #b<a>= base then
cur = cur - base
c = true
end
ret = chars[cur+1]..ret
end
if c then ret = chars[2]..ret end
return ret
end
function mult(a,b,base)
base = base or 10
local ret = ""
while #a<#b do a=chars[1]..a end
while #b<#a do b=chars[1]..b end
for i = 1,#a do
ret = ret..chars[1]
for i=1,tonumber(a:sub(i,i),base) do
ret = add(ret,b,base)
end
end
return ret
end
Arguments
a and
b are strings in base
base. The
base is optional and 10 if not given. The result is a string in base
base.
Example:
mult("B65698F7","41C64E6D",16) gives
"2ED93BAD0B84632B".
The last 32 significant bits are just the last 8 characters, so
result = mult("B65698F7","41C64E6D",16)
print(result:sub(-8))
gives
0B84632B.
(Additional symbols have to be added to
chars for higher bases than 16).