Update 1: (Another tomorrow)
1: Added support for every symbol (Except -
, _
, +
, and =
)
2: Added support for numbers (0-9)
3: Hid the tables from exploiters (The best I can at the moment)
Update 1: (Another tomorrow)
1: Added support for every symbol (Except -
, _
, +
, and =
)
2: Added support for numbers (0-9)
3: Hid the tables from exploiters (The best I can at the moment)
You could already do what this module does with some of the built-in functions:
local str = "Test string"
local nums = string.byte(str, 1, #str) -- A bunch of numbers
local strAgain = string.char(table.unpack(nums)) -- "Test string"
Now, if you added basic ciphers such as the Caesar ciper, or any industry-standard cipers, this module would be much more useful than it is now. Don’t give up, just keep improving it until it’s ready for use.
Encryption is not a valid method of securing remotes. All that does is add more stress on the server/client, and provides a false sense of security. Do not attempt to secure the client in any case; the real damage comes from unsecured remotes.
You’ve also mentioned that this module can be used to encrypt passwords. There’s a few flaws with that:
Pretty fun module! Could for sure see me using this in a puzzle or something like that in the future. Nice job!
The reason it says for encrypting passwords is because some features of games can have like a user password.
Hmm I will work on it, thanks for the feedback
Thanks for the help! (character limit)
Here are the problems:
1: The module returns nothing, you must return RoEncode
2: Both of the external modules are private
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.
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!