RoEncode v1.0, a Simple Encryption Module

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:

  1. You can’t ask players for passwords in any situation. It doesn’t matter if it’s a field that isn’t saved, Roblox ToS forbids it if it’s worded as a “password”.
  2. Passwords should be hashed, not encrypted.
7 Likes

Pretty fun module! Could for sure see me using this in a puzzle or something like that in the future. Nice job!

2 Likes

The reason it says for encrypting passwords is because some features of games can have like a user password.

Didn’t work for me :frowning:.

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

  1. The module returns the string that was Encoded/Decoded
  2. Let me fix that rq (Thanks for telling me)

Should be fixed now, thanks for reporting the bug! :slight_smile:

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.

1 Like

It’s working for me. I’ll publish this version if that’s the issue.
image

Got it working. Thanks a lot!

1 Like

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

15 Likes

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!

10 Likes

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!

2 Likes

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.

4 Likes

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!