• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community

Is there a keyword for decrypt ? (1 Viewer)

ChrisDekker

Newcomer
Joined
Sep 9, 2021
Messages
2
Reaction score
0
Hi all,

Having a transfer problem from a python script to lua.
heres the lua script i got so far


Lua:
local my_secret_key = 5
function decrypt ( secret_string , secret_number ) do
  local result = ""
  for x in secret_string do
    result = result+chr( ord ( x ) ^ int (secret_number) )
    end
  return result
end
end

print(my_secret_key, "is my secret key")


print(decrypt("alq%lv%``k%b`m`lh" , my_secret_key ) )
print("is my secret phrase")

Where's my problem, can anybody help me ?
Thank you

Chris
 

stetre

Member
Rank: I
Joined
Jan 8, 2020
Messages
89
Reaction score
49
Location
Italy
Website
github.com
It's not a keyword. There are very few of them, as you can see here.

If you'd like people to help you, you should at least post the error message.
 

ChrisDekker

Newcomer
Joined
Sep 9, 2021
Messages
2
Reaction score
0
You’re totally right, stupid rookie mistake. Heres the error message :


5 is my secret key

lua5.3: HelloWorld.lua:5: attempt to call a string value
stack traceback:
HelloWorld.lua:5: in function 'decrypt'
HelloWorld.lua:15: in main chunk
[C]: in ?
 

stetre

Member
Rank: I
Joined
Jan 8, 2020
Messages
89
Reaction score
49
Location
Italy
Website
github.com
The problem is in how you built the for loop. That's not how it works in Lua (see here).

To iterate over the characters of a string you can use utf8.codes, for example:

Lua:
for p, c in utf8.codes("il gatto e la volpe") do
    print(p, c, utf8.char(c))
end
 
Top