Base64
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| require "base64"
def encode(file,output_file)
target = File.open(output_file, 'wb')
target.truncate(target.size)
target.write(Base64.encode64(open(file,"rb").to_a.join))
target.close()
end
def decode(file,output_file)
target = File.open(output_file, 'wb')
target.truncate(target.size)
target.write(Base64.decode64(open(file,"rb").to_a.join))
target.close
end
encode("1.jpg","2.txt")
decode("2.txt","3.jpg")
|