replace sub w/ gsub, deduplicate b64 code

This commit is contained in:
Jill 2022-12-31 04:17:37 +03:00
parent a734b39238
commit 0fddc7a3e6
5 changed files with 11 additions and 7 deletions

View File

@ -58,7 +58,7 @@ CrystalGauntlet.endpoints["/downloadGJLevel22.php"] = ->(body : String): String
response += CrystalGauntlet::Format.fmt_hash({
1 => id,
2 => name,
3 => Base64.encode(description).sub('/', '_').sub('+', '-').strip("\n"),
3 => GDBase64.encode(description),
4 => level_data,
5 => version,
6 => user_id,

View File

@ -64,7 +64,7 @@ CrystalGauntlet.endpoints["/getGJLevels21.php"] = ->(body : String): String {
19 => featured,
42 => epic,
45 => objects,
3 => Base64.encode(description).sub('/', '_').sub('+', '-').strip("\n"),
3 => GDBase64.encode(description),
15 => length,
30 => original || 0,
31 => two_player,

View File

@ -16,7 +16,7 @@ CrystalGauntlet.endpoints["/uploadGJLevel21.php"] = ->(body : String): String {
description = params["levelDesc"]
if params["gameVersion"].to_i >= 20 # 2.0
description = GDBase64.decode description
description = GDBase64.decode_string description
end
if DATABASE.scalar("select count(*) from levels where id = ? and user_id = ?", params["levelID"], params["accountID"]).as(Int64) > 0

View File

@ -21,11 +21,15 @@ module CrystalGauntlet::GDBase64
extend self
def encode(v)
Base64.encode(v).sub('/', '_').sub('+', '-')
Base64.encode(v).gsub('/', '_').gsub('+', '-').strip("\n")
end
def decode(v)
Base64.decode_string(v.sub('_', '/').sub('-', '+'))
Base64.decode(v.gsub('_', '/').gsub('-', '+'))
end
def decode_string(v)
Base64.decode_string(v.gsub('_', '/').gsub('-', '+'))
end
end

View File

@ -7,7 +7,7 @@ module CrystalGauntlet::GJP
XOR_KEY = "37526"
def decrypt(pass : String)
pwd = Base64.decode(pass.sub('_', '/').sub('-', '+'))
pwd = GDBase64.decode(pass)
decrypted = ""
pwd.each.with_index() do |chr, index|
@ -24,7 +24,7 @@ module CrystalGauntlet::GJP
encrypted[index] = chr ^ XOR_KEY.byte_at(index % XOR_KEY.bytesize)
end
Base64.encode(encrypted).sub('/', '_').sub('+', '-')
GDBase64.encode(encrypted)
end
def hash(pass : String)