This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Left's profile picture

Hash or Encryption?

Started by Left, 06 April 2013 - 03:21 PM
Left #1
Posted 06 April 2013 - 05:21 PM
I have written a encrypt function but I cannot decrypt it. Can you have a try and if you can post your code please.


function enc(str, key) -- Function
local tProp = {} -- Make table
for i = 1, str:len() do -- loop for str length
  local val = tonumber(str:byte(i) * tonumber(key) + 12.6 * key / 2.8)--Byte str times keyadd 12.6 times key and divide 2.8
  table.insert(tProp, val) -- rest is to return the data
end
return table.concat(tProp)
end
1lann #2
Posted 06 April 2013 - 07:34 PM
Here ya go. I had to modify your original function slightly


function enc(str, key) -- Function
local tProp = {} -- Make table
for i = 1, str:len() do -- loop for str length
  local val = tonumber((str:byte(i) * tonumber(key) + (12.6 * key)) / 2.8)--Byte str times keyadd 12.6 times key and divide 2.8
  table.insert(tProp, val) -- rest is to return the data
end
return tostring(table.concat(tProp,"|"))
end

function dec(str, key)
local data = {}
for word in string.gmatch(str, "[^|]+") do
  local rdata = ((tonumber(word)*2.8)-(12.6*key))/key
  table.insert(data, math.floor(rdata+0.5))
end
return string.char(unpack(data))
end
Left #3
Posted 06 April 2013 - 11:54 PM
NiCE! +1
SuicidalSTDz #4
Posted 07 April 2013 - 08:37 AM
Don't encrypt. Encryption is able to be decrypted. Hashes are more secure and would take a super-computer to decode the hash, if it even can.. Just my opinion though. Nice script 1lan :)/>
ElvishJerricco #5
Posted 07 April 2013 - 11:51 AM
Don't encrypt. Encryption is able to be decrypted. Hashes are more secure and would take a super-computer to decode the hash, if it even can../>/>

This is entirely dependent on what you're trying to do. If you're just trying to store data that you'll never need to read, but will need to compare against, hashes work. If you need to be able to read the data though, you have to do encryption.
SuicidalSTDz #6
Posted 07 April 2013 - 11:53 AM
You can hash the input and compare it to the hashed data..

EDIT: I see what you are trying to say though
ElvishJerricco #7
Posted 07 April 2013 - 12:17 PM
You can hash the input and compare it to the hashed data..

EDIT: I see what you are trying to say though

Yea the idea is that you can compare an input to a hash but you can't read a hash. So for stuff like encrypted messaging, you can't use hashes.