Files
jdt-fish-client/assets/FishSingle/script/engine/utils/HaoEncrypt.ts
2024-05-01 19:13:01 +08:00

27 lines
758 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export default class HaoEncrypt {
public static encode(str: string) {
let result: string = ''
for (let i = 0; i < str.length; i++) {
// 遍历字符串
let code: number = str.charCodeAt(i) // //逐个提取每个字符并获取Unicode编码值
if (i % 2 === 0) code += 2
else code += 1
result += String.fromCharCode(code)
}
return result
}
public static decode(str: string) {
let result: string = ''
for (let i = 0; i < str.length; i++) {
// 遍历字符串
let code: number = str.charCodeAt(i) // //逐个提取每个字符并获取Unicode编码值
if (i % 2 === 0) code -= 2
else code -= 1
result += String.fromCharCode(code)
}
return result
}
}