Code: Select all
table={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r",
"s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0","_"," "}
function index(tab,key)
for i = 1,#tab do
if string.lower(tab) == string.lower(key) then
return i
end
end
end
function encrypt(key,value)
str,text=key,value
num=string.len(text)
string=string.rep(str,math.floor(num/string.len(str))) --string.sub includes syntax
remainder=num-string.len(string)
longpass=string..string.sub(str,0,remainder)
for i = 1,#string.len(text) do
if index(table,string.sub(text,0,1))+index(table,string.sub(longpass,1,1)) ~= nil then
text=string.sub(text,0,i-1)..table[(index(table,string.sub(text,0,1))+index(table,string.sub(longpass,1,1)))]..string.sub(text,i+1)
else
local temp=table[(index(table,string.sub(text,0,1))+index(table,string.sub(longpass,1,1)))-#table]
text=string.sub(text,i-1,i-1)..temp..string.sub(text,i+1)
end
end
return text
end
function love.draw()
love.graphics.print(encrypt("a","Hi"),0,0)
end
Every key is replaced with the sum of that keys numerical value in the table and the numerical value in the password repeated to be the same length as the translated strings value in the table
Let;
H=1
L=2
M=3
N=4
password is "HL"
to change = "HLLH"
1. Password is lengthened to 4 characters long (repetition) ("HLHL")
2. String is translated by adding password and string
HLLH + HLHL
HLLH (1221)
HLHL (1212) +
HNMM (1433)
Sums do not cross over, but instead re-wrap around the table when they exceed #table As in:
#table is 3
Sum is 4
Sum becomes 1
(1,2,3) *loop around* (1)
Thanks in advance