# mk_nya_code | Marsho AI
Kawaii, Intelligent and Easy to Extend

Skip to content

# Module `nonebot_plugin_marshoai.plugins.twisuki_megakits.mk_nya_code` ​

### async func `nya_encrypt(msg: str)` ​

Source code or View on 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)` ​

Source code or View on 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` ​

- Description: 大写字母 A-Z

- Default: `chr(65 + i)`

### var `char` ​

- Description: 小写字母 a-z

- Default: `chr(97 + (i - 26))`

### var `char` ​

- Description: 数字 0-9

- Default: `chr(48 + (i - 52))`

### var `char` ​

- Description: 特殊字符 +

- Default: `chr(43)`

### var `char` ​

- Description: 特殊字符 /

- Default: `chr(47)`