Jump to content

teaDecode problem


xTravax

Recommended Posts

hi i am trying to encode image code with tea function and then later when i need it i decode it but it doesnt work

local file = fileOpen("rec.jpg") 
local content = fileRead(file,fileGetSize(file)) 
local encode = teaEncode(content,"#qa$aJOAio4jikj!") 
fileClose(file) 
fileDelete("rec.jpg") 
local file = fileCreate("rec.jpg") 
fileWrite(file,encode) 
fileClose(file) 
  
function restoreFile() 
fileDelete("rec.jpg") 
local image = fileCreate("rec.jpg") 
fileWrite(image,teaDecode(encode,"#qa$aJOAio4jikj!")) 
fileClose(image) 
end 
addCommandHandler("restore",restoreFile) 

you can try any picture and it wont work for unknown reason

when it "restores" the file it makes 4 bytes long text like

˙Ř˙ŕ 

please help

Link to comment
  • Other Languages Moderators

Try encode binary data to base64 and decode base64 encoded string back to binary.

local file = fileOpen("rec.jpg") 
local content = fileRead(file,fileGetSize(file)) 
--local encode = teaEncode(content,"#qa$aJOAio4jikj!") 
local encode = teaEncode(base64Encode(content),"#qa$aJOAio4jikj!") 
fileClose(file) 
fileDelete("rec.jpg") 
local file = fileCreate("rec.jpg") 
fileWrite(file,encode) 
fileClose(file) 
  
function restoreFile() 
fileDelete("rec.jpg") 
local image = fileCreate("rec.jpg") 
--fileWrite(image,teaDecode(encode,"#qa$aJOAio4jikj!")) 
fileWrite(image,base64Decode(teaDecode(encode,"#qa$aJOAio4jikj!"))) 
fileClose(image) 
end 
addCommandHandler("restore",restoreFile) 

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...