Merge pull request #21 from Twisuki/main

修复了NyaCode解码问题 & 修改了猫语内容
This commit is contained in:
Nya_Twisuki 2024-12-07 14:27:13 +08:00 committed by GitHub
commit add6058bee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,7 @@ NyaCodeCharset = [
'', '', '?', '~'
]
NyaCodeSpecialCharset = [
'', '!', '...', '....'
'', '!', '...', '..'
]
NyaCodeEncode = {}
for i in range(64):
@ -22,7 +22,10 @@ def nya_encode(msg: str):
msg_nyastr = ''.join(NyaCodeEncode[base64_char] for base64_char in msg_b64str)
result = ""
for char in msg_nyastr:
if random.random() < 0.2:
if char == '' and random.random() < 0.5:
result += "!"
if random.random() < 0.25:
result += random.choice(NyaCodeSpecialCharset) + char
else:
result += char
@ -31,7 +34,7 @@ def nya_encode(msg: str):
# NyaCode Decrypt
def nya_decode(msg: str):
msg = msg.replace('', '').replace('.', '').replace('!', '')
msg = msg.replace('', '').replace('!', '').replace('.', '')
msg_nyastr = []
i = 0
if len(msg) % 3 != 0 :
@ -45,6 +48,7 @@ def nya_decode(msg: str):
except Exception:
return "这句话不是正确的猫语"
msg_b64str = ''.join(NyaCodeDecode[nya_char] for nya_char in msg_nyastr)
msg_b64str += "=" * (4 - len(msg_b64str) % 4)
try:
result = base64.b64decode(msg_b64str.encode()).decode()
except Exception: