Issue while stress testing my generator and encryption module

I ran into a issue. Not sure if it’s my script or it’s Roblox itself, or it’s just a module cooldown.
I am stress testing my generator module, and encryption module.
My generator module can generate a multi-string that has numbers and uppercase - lower case letters.
It can generate to any length of the number given.
My encryption module uses the generator module to make an encrypted multi-string, and gives that back when done.
It requires a KeyCode, and the string or multi-string that it can encrypt.
The Keycode helps find the thing that you have encrypted, and then it will return what you have given it to encrypt. AKA, it decrypts it.

What it’s not doing during the stress test is it’s not giving back what I wanted to encrypt, and instead leaves it blank.
plnm
Nothing is wrong with my encryption module, or the script that is requiring it.
Encryption module:
It’s using a dictionary.
It’s using a table to store in the dictionary.
The key would be the keycode.
There will be three values, the keycode, encrypted, decrypted.
During the stress test, only 1 result was available.
Also not to mention, it also checks if the thing that you wanted to encrypt was a string, and if it wasnt then it doesnt do anything. If not then it will do something. I am using typeof
Script:

repeat
local a = 1
print('Attempts:'..a)
local test = require(game.ReplicatedStorage.Generator)
local KeyC = test:Generate()
local t = 'Stress testing.'
test = require(script.Parent.EncryptorHandler)
print(test:Encrypt(t,KeyC))
print(test:Decrypt(KeyC))
a = a + 1
until nil

The variable a is declared inside of the loop, causing the attempts to always be one.
Also, the error appears to be with the decrypting process, not the encrypting.

By any chance, are you using numbers to encrypt and decrypt? Other than that I cannot see any problems with the code.

(I was making an encryptor once and it failed because the numbers it needed were larger than what roblox supports proof)

The numbers to encrypt and decrypt, that’s in the generator.
The generator does use numbers.
It uses one variable to make a letter, and then a number.
And the decrypting process,

-- _H is the dictionary.
function EH:Decrypt(KeyCode)
	for _,_1 in pairs(_H) do
		if _1[1] == KeyCode then
			local howmany = #_H
			for i = 1,howmany do
				if _H[i][1] == KeyCode then
					table.remove(_H,_H[i])
				end
			end
			return(_1[3])
		else
			-- nothing
		end
	end
end

I think I have found the error, you are removing the value from the array (line 8), it is causing it to not exist the next time the code runs, this is why it works on the first run.

function EH:Decrypt(KeyCode)
	for i,v in pairs(_H) do
		if v[1] == KeyCode then
			table.remove(_H, i)
			return v[3]
		end
	end
end

Not exactly.

function EH:Decrypt(KeyCode)
	print('Decrypting: '..KeyCode)
	for _,_1 in pairs(_H) do
		if _1[1] == KeyCode then
			local howmany = #_H
			local Decr = _1[3]
			for i = 1,howmany do
				if _H[i][1] == KeyCode then
					table.remove(_H,_H[i])
				end
			end
			return(Decr)
		else
			-- nothing
		end
	end
end

Did a little re-arrangement.
Still does the same thing.
I found the issue.
DE

Try doing the code but remove the table.remove. (So that all the values should be in there)

Completely removed the part that tried to find it’s location within the dictionary.LMO
Still happens.
I think that it’s doing it too quickly, aka it’s not being created fast enough.

function EH:Decrypt(KeyCode)
	print('Decrypting: '..KeyCode)
	for _,_1 in pairs(_H) do
		if _1[1] == KeyCode then
			local howmany = #_H
			local Decr = _1[3]
			return(Decr)
		else
			-- nothing
			print('DOESNT EXIST: '..KeyCode)
		end
	end
end

I did more arrangements. I got a different result.
I’m not using a pre-built table.VMPG

Try adding a one second delay inbetween the encryption and decryption.
Is the dictionary using key,value pairs or is it just in a list?

key,value pair: {["Q15Y8U13r" = {"c7M19...", "..."}]}
or
list: {{"Q15Y8U13r", "...", "..."}, ...}

Also, all the attempts after one are failing (just something I noticed)

It’s using key,value pairs.
It’s importing a table into the key, and then using table.insert to the table 3 values.
Adding a 1 second delay didn’t fix it.

Well the issue you have is the fact your not actually returning the key at all.

When you do this:

local howmany = #_H
for i = 1,howmany do...

You are treating it as a table, not a dictionary. Your cycling through the results.

Instead you will want to do:

for key, data in pairs(_H) do...

Then match, remove from the table if necessary and then simply do

return(key, data)

When you do return(_1[3]) you are only returning the content, not the key itself.

marked for continue code from there.

That’s not what I put

for.
I put it so I can find the key in the dictionary.
And then I remove it from the dictionary.
Also, it isn’t supposed to return the keycode. It’s supposed to return the thing that the user wanted to encrypt
If it returned the keycode, then what’s the point in decrypting?

I don’t see the purpose for the 3 values, in my experience with encryption it should be something like

local function enc(str, pass)
	local s = ""
	local n = 0
	for i=1,pass:len() do
		n = n + pass:sub(i,i):byte()
	end
	for i=1,str:len() do
		s = s .. string.char((str:sub(i, i):byte() + n) % 256)
	end
	return s
end
local function dec(str, pass)
	local s = ""
	local n = 0
	for i=1,pass:len() do
		n = n + pass:sub(i,i):byte()
	end
	for i=1,str:len() do
		s = s .. string.char((str:sub(i, i):byte() + 25600000 - n) % 256)
	end
	return s
end
print(dec(enc("how is your day going", "hello"), "hello"))

should work (even though it’s low level encryption)

Edit: A version that looks similar is

local _H = {}
local function enc(key, str, pass)
	local s = "" -- you can change this area out to whatever encryption you want
	local n = 0
	for i=1,pass:len() do
		n = n + pass:sub(i,i):byte()
	end
	for i=1,str:len() do
		s = s .. string.char((str:sub(i, i):byte() + n) % 256)
	end
	_H[key] = s
end
local function dec(key, pass)
	local str = _H[key] -- same with this area as long as it does the opposite as the encryption
	local s = ""
	local n = 0
	for i=1,pass:len() do
		n = n + pass:sub(i,i):byte()
	end
	for i=1,str:len() do
		s = s .. string.char((str:sub(i, i):byte() + 25600000 - n) % 256)
	end
	return s
end
enc("hi", "how is your day going", "hello")
print(dec("hi", "hello"))

It uses a key to store the value in the table and then retrieves it using the same key.

Syntax:

enc(key, string, password)
dec(key, pass) -- returns the decrypted version

I must have misinterpreted your question then, also the bit you quoted is from post 3.

Your methodology is pretty inefficient when reviewing your code from post 3. I’m just going to mark something on the code you provided which I find slightly useless.

function EH:Decrypt(KeyCode)
	for _,_1 in pairs(_H) do
		if _1[1] == KeyCode then -- point 1a
			local howmany = #_H
			for i = 1,howmany do
				if _H[i][1] == KeyCode then -- point 1b
					table.remove(_H,_H[i])
				end
			end
			return(_1[3])
		else
			-- nothing
		end
	end
end

Point 1:
You cycle through and confirm this is the right table (a), you then proceed to cycle through again but you may as well just skip the (a) entirely if (b) is going to do the same check (as it can also check for presence equally).

Also, I fail to see why _H even needs to be a dictionary when you do not treat it as one. This is inherently apparent from your methodology and the usage of _ in your code. The moment you stuck a numeric (in this case i would be your numeric in _H[i]) as your ‘key’ you essentially did the exact same thing as a table.

There, now it’s being treated as a table.
I used the dictionary for easy finding so that I won’t have to go and get it again.
It still pauses for unknown reasons though.
It’s probably the generator module.
Verified it. It’s the generator module.
It’s not going past stage 2(before the line where the keycode is generated)

I mean I would definitely use a dictionary for simplicity purposes, that way you can simply do table[key] which stops the need to cycle through results and also does a presence check automatically. To then clear the key you’d set the value to nil.

I was awkwardly going to ask if the generator module was fine, but then I found it difficult to decide where the error in the process would be.

The issue was inside the generator module the whole time.
It was because it was going over the required length of the desired string.
I removed every number inside the table that was over 9.
Now it’s going perfectly fine without pauses.