Created
October 5, 2024 14:10
-
-
Save EggToaster/24031eb2b977c23f2ead0e1b71b17c60 to your computer and use it in GitHub Desktop.
A script to turn two string values to two string=>hex=>B64 value, then append it in file(Dual battery rename creator)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---@diagnostic disable: need-check-nil --SHUTUP DAMN LOGS | |
function toHex(str) | |
return (str:gsub(".", function(char) return string.format("%02x", char:byte()) end)) | |
end | |
function toB64(data)--ew, b64 sucks | |
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' | |
return ((data:gsub('.', function(x) | |
local r,b='',x:byte() | |
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end | |
return r; | |
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x) | |
if (#x < 6) then return '' end | |
local c=0 | |
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end | |
return b:sub(c+1,c+1) | |
end)..({ '', '==', '=' })[#data%3+1]) | |
end | |
function strToB64(str) | |
return toB64(toHex(str)) | |
end | |
local f = io.open("Base.txt","r") | |
local b = f:read("a") | |
f:close() | |
local f = io.open("Lists.txt","r") | |
local l = f:read("a") | |
f:close() | |
local res = "" | |
---@diagnostic disable-next-line: param-type-mismatch | |
for v, _ in string.gmatch(l,"([^\n]+)") do | |
print(b) | |
local to = "X"..v:sub(2,4) | |
print(v.." to "..to) | |
local vh, th = toHex(v),toHex(to) | |
print(v.." goes "..vh) | |
print(to.." goes "..th) | |
local vb, tb = toB64(vh),toB64(th) | |
print(vh.." goes "..vb) | |
print(th.." goes "..tb) | |
local result = b:gsub("SC_BASE",v):gsub("SC_TO",to):gsub( | |
"SC_FROM",vb):gsub("SC_AFTER",tb) | |
print(result) | |
res = res..result.."\n" | |
end | |
print("\nDone!\n") | |
print(res) | |
local f = io.open("Done.txt","w") | |
f:write(res) | |
f:close() | |
print("\n\n\nDONE!!!!!!\n\n\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: it excepts two files, so I will upload here.
The file is enough to do the rename job, which is why I made this. It can be used as an example too.
Base.txt:
Lists.txt: