- 1,748
- Posts
- 15
- Years
- Age 28
- Nearby my feet.
- Seen Apr 18, 2021
Well, today I was thinking, hey why shouldn't I encrypt my save, but I had a few problems, I didn't want something easy to crack, so I came up with the Linear Cong encryption, it's basically the same as random encryption, but it uses the LinearCong class that I think almost no one knew existed in essentials.
Anyways enough talk, here's the script:
By default, this script automatically encrypts your saves, making it a lot more difficult to crack (but this comes at the cost of nice and fast saves, well, it only slows it down by about 4 or 5 seconds which isn't too bad)
Anyways enough talk, here's the script:
By default, this script automatically encrypts your saves, making it a lot more difficult to crack (but this comes at the cost of nice and fast saves, well, it only slows it down by about 4 or 5 seconds which isn't too bad)
Code:
################################################################################
# Linear Cong Hasher
# By Rei
# Credits Required
################################################################################
# Uses Linear Cong Random methods to encrypt your data.
#
# NOTICE: This will automatically encrypt your save data. UNLESS you set the
# variable "USE_HASHER" to false
#
# WARNING: DO NOT AT ANY CONDITION MODIFY THE CODE DOWN THERE AFTER MAKING YOUR
# FIRST ENCRYPTED SAVE, OTHERWISE YOUR DATA COULD GET CORRUPTED!
#
# How to Use (Save Encryptions):
# * Insert this script
# * Set the variable "USE_HASHER" to true (this is the default setting)
# * Test saving
#
# How to Use (Object Encryptions):
# * To Encrypt call: object.lch_encrypt
# * To Decrypt call: encrypted_object.lch_decrypt
#
# How to Use (Encryptions):
# * To Encrypt call: LinearCongHasher.encrypt(data string)
# * To Decrypt call: LinearCongHasher.decrypt(encrypted data string)
#
################################################################################
USE_HASHER = true # Use the Hasher for SAVE DATA only (the other data cannot be
# encrypted due to RMXP needing to read data)
ENCRYPTION_SALT = "VVvvCCccMMmmNNnnCvCCCvvBBBcCCbb+"
module LinearCongHasher
def self.saltToKey(salt=ENCRYPTION_SALT)
return salt.hash ^ salt[0] * salt[0] - salt[salt.length-1]
end
def self.getCryption(index, r1, r2)
r1=r1.round
r2=r2.floor
return (index + r1 * r2) ^ (index + r1 + r2)
end
def self.encrypt(data)
n = LinearCongRandom.new(6, 7, saltToKey)
key = [n.getNext, n.getNext, n.getNext, n.getNext, n.getNext, n.getNext,
n.getNext, n.getNext, n.getNext, n.getNext, n.getNext, n.getNext, n.getNext]
for i in 0...data.length
k = key[i % key.length]
total = getCryption(getCryption(i, k, n.getNext), n.getNext, k)
data[i] = (data[i] - total) % 255
end
return data
end
def self.decrypt(data)
n = LinearCongRandom.new(6, 7, saltToKey)
key = [n.getNext, n.getNext, n.getNext, n.getNext, n.getNext, n.getNext,
n.getNext, n.getNext, n.getNext, n.getNext, n.getNext, n.getNext, n.getNext]
for i in 0...data.length
k = key[i % key.length]
total = getCryption(getCryption(i, k, n.getNext), n.getNext , k)
data[i] = (data[i] + total) % 255
end
return data
end
end
class Object
def lch_encrypt
return LinearCongHasher.encrypt(Marshal.dump(self))
end
end
class String
def lch_decrypt
return Marshal.restore(LinearCongHasher.decrypt(self))
end
end
module Marshal
class << self
alias lch_load load
alias lch_dump dump
end
def self.load(file)
data = lch_load(file)
if !file.is_a?(String) && file.path == RTP.getSaveFileName("Game.rxdata") &&
USE_HASHER && data.is_a?(String)
return data.lch_decrypt
end
return data
end
def self.dump(data, file=nil)
if file && file.path == RTP.getSaveFileName("Game.rxdata") && USE_HASHER &&
!data.is_a?(Game_Screen) && !data.is_a?(Game_Map) &&
!data.is_a?(Game_Player) && !data.is_a?(Game_System) &&
!data.is_a?(PokemonMapFactory)
data = data.lch_encrypt
end
if !file
file = File.open("Temp", "wb")
tf=true
end
data = lch_dump(data, file)
if tf
file.close
file = File.open("Temp", "rb")
data = file.read
file.close
File.delete("Temp")
end
return data
end
end
Last edited: