Jump to content

teaEncode / teaDecode - in-ou data mismatch


Recommended Posts

Hello,

Can somebody explain me, how could be that possible:

	local file = fileOpen("loading.dds")   
	local size = fileGetSize(file)	
	local raw = fileRead(file, size)  
	fileClose(file)

	local encoded = teaEncode(raw, "0123456789ABCDEF")
	local dencoded = teaDecode(encoded, "0123456789ABCDEF")
	outputDebugString("Raw: " .. string.len(raw))	
	outputDebugString("Encoded: " .. string.len(encoded))	
	outputDebugString("Decoded: " .. string.len(dencoded))	

	if dencoded == raw then
		outputDebugString("Test PASSED")	
	else
		outputDebugString("Test FAILED")	 
	end

Result:

399da23e62a447039ec80d43d6168efc.jpeg

 

Client v1.5.4-release-11354

Oh... never-mind. 

Tea works only with text-data. Not binary. 

In order to fix this - wrap data in-to Base64 before encoding. And unwrap after decode.


	local encoded = teaEncode(base64Encode(raw), "0123456789ABCDEF")
	local dencoded = base64Decode(teaDecode(encoded, "0123456789ABCDEF"))
	outputDebugString("Raw: " .. string.len(raw))	
	outputDebugString("Encoded: " .. string.len(encoded))	
	outputDebugString("Decoded: " .. string.len(dencoded))	
	if dencoded == raw then
		outputDebugString("Test PASSED")	
	else
		outputDebugString("Test FAILED")	 
	end
Edited by haron4igg
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...