Skip to content

Instantly share code, notes, and snippets.

@ChuckieChen945
Created November 29, 2024 07:53
Show Gist options
  • Save ChuckieChen945/07ef6cd3687d36576a4603cb999a06f3 to your computer and use it in GitHub Desktop.
Save ChuckieChen945/07ef6cd3687d36576a4603cb999a06f3 to your computer and use it in GitHub Desktop.
用于构造scoop中的下载链接,使scoop cach中的文件命名和根据url重命名后的文件名一至
# pyton312
# pip install numba
import hashlib
from concurrent.futures import ProcessPoolExecutor, as_completed
from numba import jit
import numpy as np
from multiprocessing import Manager
import string
# changeable = string.ascii_letters+string.digits
changeable = ['']
url_list = [
"https://github.com/[xxx]#b977452.7z[xxx]"
]
result=[None ]* len(url_list)
# 使用 numpy 数组加速计算
@jit(nopython=True)
def calculate_index_range(start, end):
return np.arange(start, end) # 使用 numpy 数组代替 range
def calculate_sha256(hex_value,url1,url2,url3,letter):
data = url1+ hex_value + url2+ letter +url3 # 要进行加密的数据
data_sha = hashlib.sha256(data.encode('utf-8')).hexdigest()
return data_sha
def task(index, stop_event,url,letter):
# 16^7 = 268435456
# 268435456 / 32 = 8388608
url1,url2,url3 = url.split('[xxx]')
for i in calculate_index_range(index * 8388608, (index + 1) * 8388608):
hex_value = f"{i:07x}" # 输出7位16进制,使用小写字母
data_sha = calculate_sha256(hex_value,url1,url2,url3,letter)
if data_sha[:7] == hex_value:
# print(f"Found: {hex_value}")
stop_event.value = True
raise Exception(hex_value)
def run_tasks(url,letter):
manager = Manager()
stop_event = manager.Value('b', False) # 使用共享变量停止任务
with ProcessPoolExecutor(max_workers=32) as executor:
futures = []
for i in range(32):
futures.append(executor.submit(task, i, stop_event,url,letter))
for future in as_completed(futures):
try:
future.result() # 处理任务的返回值或异常
except Exception as e:
stop_event.value = True # 设置停止信号
for future in futures:
future.cancel() # 取消未执行的任务
return str(e)
return None
if __name__ == '__main__':
for letter in changeable:
for index, url in enumerate(url_list):
result[index] = run_tasks(url,letter)
tag = False
for r in result:
if r is None:
tag = True
break
# 全找到了hash
if tag == False:
print(result)
print(letter)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment