You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

批处理生成大数遇32位精度限制报错,求SHA512破解方案

解决批处理大数字计数器的32位精度限制问题

批处理的set /a命令仅支持32位有符号整数(最大值为2147483647),你的目标数字范围(16500000000~17000000000)远超这个上限,因此会触发精度错误。可以通过字符串逐位运算来实现大数字的递增,以下是修改后的脚本:

@echo off
setlocal enabledelayedexpansion

set "start_num=16500000000"
set "end_num=17000000000"
set "current=%start_num%"

:loop
    :: 输出当前数字到文件
    echo !current! > .\Unhashed\!current!.txt
    
    :: 大数字递增逻辑
    set "num=!current!"
    set "new_num="
    set "carry=1"
    :: 从最后一位开始逐位处理进位
    for /l %%i in (10,-1,0) do (
        set "digit=!num:~%%i,1!"
        set /a "new_digit=digit + carry"
        if !new_digit! equ 10 (
            set "new_digit=0"
            set "carry=1"
        ) else (
            set "carry=0"
        )
        set "new_num=!new_digit!!new_num!"
    )
    set "current=!new_num!"
    
    :: 检查是否到达结束值
    if "!current!" equ "%end_num%" goto end
    ping localhost -n 1 >NUL
goto loop

:end
pause
endlocal

关键改进说明:

  • 启用enabledelayedexpansion确保循环中变量能实时更新。
  • 通过字符串截取逐位处理数字,手动计算进位,完全避开set /a的32位限制。
  • 保留原脚本的文件生成逻辑,同时修复计数器失效问题。

优化建议:无需生成文件直接哈希比对

生成大量文本文件会占用磁盘空间且效率低下,建议直接在脚本中计算数字的SHA512哈希并与目标值比对,示例如下:

@echo off
setlocal enabledelayedexpansion

set "start_num=16500000000"
set "end_num=17000000000"
set "target_hash=你的目标SHA512哈希值"
set "current=%start_num%"

:loop
    :: 计算当前数字的SHA512哈希(去除空格)
    for /f "delims=" %%a in ('echo !current! | certutil -hashfile - SHA512 ^| find /v "SHA512" ^| find /v "CertUtil"') do (
        set "current_hash=%%a"
        set "current_hash=!current_hash: =!"
    )
    
    :: 比对哈希,匹配则输出结果
    if "!current_hash!" equ "%target_hash%" (
        echo 找到匹配值:!current!
        goto end
    )
    
    :: 大数字递增逻辑
    set "num=!current!"
    set "new_num="
    set "carry=1"
    for /l %%i in (10,-1,0) do (
        set "digit=!num:~%%i,1!"
        set /a "new_digit=digit + carry"
        if !new_digit! equ 10 (
            set "new_digit=0"
            set "carry=1"
        ) else (
            set "carry=0"
        )
        set "new_num=!new_digit!!new_num!"
    )
    set "current=!new_num!"
    
    if "!current!" equ "%end_num%" (
        echo 未找到匹配值
        goto end
    )
goto loop

:end
pause
endlocal

注意事项:

  • 替换你的目标SHA512哈希值为实际需要比对的哈希字符串(需去掉哈希中的空格)。
  • certutil是Windows自带工具,无需额外安装即可用于计算哈希。

内容的提问来源于stack exchange,提问作者Korrupt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 09:01:28