Skip to content

模块 nonebot_plugin_marshoai.plugins.twisuki_megakits.mk_nya_code


async func nya_encrypt(msg: str)

源代码在GitHub上查看
python
async def nya_encrypt(msg: str):
    result = ''
    b64str = base64.b64encode(msg.encode()).decode().replace('=', '')
    nyastr = ''
    for b64char in b64str:
        nyastr += NyaCodeEncode[b64char]
    for char in nyastr:
        if char == '呜' and random.random() < 0.5:
            result += '!'
        if random.random() < 0.25:
            result += random.choice(NyaCodeSpecialCharset) + char
        else:
            result += char
    return result

async func nya_decrypt(msg: str)

源代码在GitHub上查看
python
async def nya_decrypt(msg: str):
    msg = msg.replace('唔', '').replace('!', '').replace('.', '')
    nyastr = []
    i = 0
    if len(msg) % 3 != 0:
        return '这句话不是正确的猫语'
    while i < len(msg):
        nyachar = msg[i:i + 3]
        try:
            if all((char in NyaCodeCharset for char in nyachar)):
                nyastr.append(nyachar)
            i += 3
        except Exception:
            return '这句话不是正确的猫语'
    b64str = ''
    for nyachar in nyastr:
        b64str += NyaCodeDecode[nyachar]
    b64str += '=' * (4 - len(b64str) % 4)
    try:
        result = base64.b64decode(b64str.encode()).decode()
    except Exception:
        return '翻译失败'
    return result

var char

  • 说明: 大写字母 A-Z

  • 默认值: chr(65 + i)

var char

  • 说明: 小写字母 a-z

  • 默认值: chr(97 + (i - 26))

var char

  • 说明: 数字 0-9

  • 默认值: chr(48 + (i - 52))

var char

  • 说明: 特殊字符 +

  • 默认值: chr(43)

var char

  • 说明: 特殊字符 /

  • 默认值: chr(47)

文档完善中,欢迎提出建议或帮助我们完善。