- The module returns the string that was Encoded/Decoded
- Let me fix that rq (Thanks for telling me)
Should be fixed now, thanks for reporting the bug!
The bug has not been fixed for this reason: at the end of the modulescript you don’t actually return anything. You must return the table or it will error. Here’s an example of right and wrong:
-- correct
local module = {}
return module -- returned the module
--incorrect
local module = {}
return -- didn't return anything
Edit: There’s another bug: you can’t require the module using require(9327178091) because the modulescript is named RoEncode instead of MainModule. Renaming the modulescript to MaiinModule would allow people to require it into their game, which is good since it gives the latest version.
Edit 2: The two external modules have the above errors just like the main module.
This is a fun exercise (and I’m happy you’ve made and open sourced this!), but please do not rely on it for security.
Some people have called this out as not being encryption, but that’s incorrect. It is encryption, but it’s so weak that by modern standards it is barely considered such.
The encryption algorithm used here is known as a simple monoalphabetic substitution cipher. These are thousands of years old (Simple monoalphabetic substitution ciphers like the Atbash cipher have been found around 600 to 500 BCE) and are absolutely trivial to break. Substitution ciphers are fun to play around with, like those decoder rings you’d find in cereal boxes, because they are so simple to break that a person can do it with a pencil and 5 minutes of time. Many people solve such ciphers for recreation, as with cryptogram puzzles in the newspaper.
To a computer, that’s instantaneous and is therefore of no security value. This module is useful for education and practice, but not actual usage in a production environment. It’s great that you’ve made this and I hope you find cryptography interesting and dive into more!
For a more secure and modern cryptographic encryption, I’ve written a module that wraps the RbxNet library with authenticated encryption of Roblox networking using Elliptic-curve Diffie–Hellman key exchanges and ChaCha20 ciphering.
You can find that here: https://github.com/boatbomber/EncryptedNet
You don’t need to store giant lookup tables of every character. Characters already have a number associated with them- their byte representation! We can use string.byte
to turn the string into a table of numbers. From there, we can mutate those numbers algorithmically in a reversible fashion (eg: shifting by some constant) for a more robust substitution module that handles any character in very few lines of code!
local module = {}
local SHIFT = 5
function module:Encode(input: string)
local bytes = table.pack(string.byte(input, 1, #input))
for i, byte in ipairs(bytes) do
bytes[i] = byte+SHIFT
end
return string.char(table.unpack(bytes))
end
function module:Decode(input: string)
local bytes = table.pack(string.byte(input, 1, #input))
for i, byte in ipairs(bytes) do
bytes[i] = byte-SHIFT
end
return string.char(table.unpack(bytes))
end
return module
local SimpleCipher = require(script.SimpleCipher)
local encoded = SimpleCipher:Encode("Hello DevForum friends! This is a shift substitution cipher!")
local decoded = SimpleCipher:Decode(encoded)
print(encoded)
print(decoded)
Output:
Mjqqt%Ij{Ktwzr%kwnjsix&%Ymnx%nx%f%xmnky%xzgxynyzynts%hnumjw&
Hello DevForum friends! This is a shift substitution cipher!
You may notice that it’s very easy to spot the patterns here- the % character is space, f is a, etc. We can mix it up a little and make the substitution depend on the position within the string, so even double letters like the ll in Hello won’t be the same character!
function module:Encode(input: string)
local bytes = table.pack(string.byte(input, 1, #input))
for i, byte in ipairs(bytes) do
bytes[i] = byte + (i%SHIFT + 1)
end
return string.char(table.unpack(bytes))
end
function module:Decode(input: string)
local bytes = table.pack(string.byte(input, 1, #input))
for i, byte in ipairs(bytes) do
bytes[i] = byte - (i%SHIFT + 1)
end
return string.char(table.unpack(bytes))
end
Jhpqp"Gi{Gquyr!humjofv%%Ujlw%ju#e%tjljy!uxfxukwyyjqq$hjrkiw"
Hello DevForum friends! This is a shift substitution cipher!
The point of this module was:
A: Learn more about Lua and how it works
B: Provide a module that can convert text into codes (Like an escape room or smth)
Thank you! The creation of the module was mostly for me and @Luna_Adair to learn more about Lua. We open sourced it to help other developers understand how certain functions work. Before we made this module, I didn’t know what the string.sub()
function did. Now I do!
I made a little module containing @boatbomber’s module and RoEncode with my StringScrambler.
Link : EncryptionModule - Roblox.
Example script :
local EncryptionModule = require(script.EncryptionModule)
print(EncryptionModule:ScrambleString("Hello World!"))
task.wait()
local RoEncode_Encrypted = EncryptionModule:SimpleEncryption("Hello World!")
print(RoEncode_Encrypted)
task.wait()
print(EncryptionModule:DecodeSimpleEncryption(RoEncode_Encrypted))
task.wait()
local BoatCyrpted = EncryptionModule:AdvancedEncryption("Hello World!")
print(BoatCyrpted)
task.wait()
print(EncryptionModule:DecodeAdvancedEncryption(BoatCyrpted))
Hope people enjoy!
Should I make a post about it to get all of our work out there or for learning opportunity for people.
- Yes
- No
0 voters
WARNING! THIS MODULE SHOULD NOT BE USED FOR PASSCODE SECURING WHATSOEVER. READ THIS FOR MORE : RoEncode v1.0, a Simple Encryption Module - #36 by boatbomber
Calling my simple shift substitution cipher “AdvancedEncryption” got a good laugh out of me, so thanks for that. I will reiterate- it is useful for academic/educational purposes only. Please don’t actually use it, and please include that disclaimer in the source code. I don’t want people to see that and think that boatbomber is calling a substitution cipher secure encryption. It’d be best if you link my earlier reply with my detailed explanation of why this is not meant for real world use.
Glad it got you a laugh lol.
Your module is a bit more advanced so that’s why I put it like that. For the poll I’ll change the poll question a bit so maybe consider revoting.
Thanks!
Fixed my module post thanks all!
I meant to link my reply inside the module, not inside this thread. My reply is already in this thread!
Hello! By the way thank you for your response, we will take the necessary steps to make this a reliable security, we’re new when it comes to this kind of topic and love to learn, thank you for these sources that we can look upon.
We’ll make sure it’s safe and good for you all down the road!
Also it’s my birthday today and you, boatbomber, are my idol when it comes to coding, for you to reply to our topic made my birthday a bit better!
Will do sorry a ton. Thanks for the heads up. lol
Happy birthday! It’s great to see new people picking up the trade and learning new things. Encryption is a massive topic with lots of depth, so you’ve got a lot of awesome stuff ahead of you!
It’s my first time working with game security, but lol I’m not a new developer
Happy birthday ! Glad @boatbomber could make it better. Thanks for open-sourcing this because it has given me inspiration!
Happy birthday , thanks to boatbomber’s response, this may allow me to improve my own private encryption module
I wish you the best on the cryptography field (if I’m right, encryption is cryptography)