Custom encryption module doesn't work

I am working on an encryption system called “Universe99”. really horrible name, ik
However, when I decrypt something with a piece of test code, it gives me this output result:

This is my test code that I used in the command bar:

local thing = require(game.ServerScriptService.ServerLogic.Modules.Encryption.Universe99)
local e = thing.toUniverse("Whydoidothistomahself")
 print(e)
 print(thing.toWorld(e))

and its output (with some hidden unicodes):

  19:46:57.881  Xj|htokw}rt}|qy…x€{  -  Server (This is the encoded result, from toUniverse)
  19:46:57.881  Whydoidothisnl`gcc  -  Server (This is the decoded result, from toWorld)

As you can see, the output returns some correct letters, but then just ends up not trying to receive the correct letters. This is the module code for my encoding system:

local universe99 = {}

function universe99.toUniverse(str)
	assert(typeof(str) == "string", "Argument #1 of toUniverse must be a string.")
	local encrypted = ""
	
	for i=1, #str do
		local letter = str:sub(i, i)
		local point = utf8.codepoint(letter) + i
		
		encrypted = `{encrypted}{utf8.char(point)}`
	end
	
	return encrypted
end

function universe99.toWorld(str)
	assert(typeof(str) == "string", "Argument #1 of toWorld must be a string.")
	local decrypted = ""

	for i=1, #str do
                -- pcall because roblox screams errors for absolutely no reason
		local letter = str:sub(i, i)
		local success, point = pcall(function()
			return utf8.codepoint(letter)
		end)
		
		if success and typeof(point) == "number" then
			point -= i
		else
			continue
		end

		decrypted = `{decrypted}{utf8.char(point)}`
	end
	
	return decrypted
end

return universe99
1 Like

Basically there are ids (like utf8.char(10)) that returns nothing so your decryption gets messed up since it doesn’t consider the nothing from the string you encrypted because it can’t see it. I recommend you just use your own set of characters to go through when encrypting and decrypting.

Okay then. Didn’t know that some characters from the utf8 library don’t return anything (Edit: am using gzip compression now)

1 Like

Oops. Just found out it doesn’t return nothing, it returns a \n so yeah that could be the one messing it up

Wait it’s actually not the one causing the problem, I think it’s the whole script itself. It’s when you do this, it only prints for the 18 characters and not the whole string.

Some points are invalid so it’s skipping it (127 I don’t know why but it’s not being accepted). So yeah I think using your own sets of characters would be easier lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.