description class _BitEncrypt { private readonly logTag = `[BitEncrypt]:` ; private _encryptKey : string = "EskKbMvzZBILhcTv" ; public set encryptKey ( value ) { this . _encryptKey = value ; } description public get encryptKey ( ) { return this . _encryptKey ; } description param content param key public decode ( content , key ? ) { return this . _code ( content , key ) ; } description param content param key public encode ( content , key ? ) { return this . _code ( content , key ) ; } private _code ( content , key ) { let result = this . _check ( content , key ) ; if ( result . isOK ) { let contentCharCode = [ ] ; for ( let i = 0 ; i < content . length ; i ++ ) { contentCharCode . push ( content . charCodeAt ( i ) ) ; } let index = 0 ; let ch = "" ; let regex = /[\w\d_-`~#!$%^&*(){}=+;:'"<,>,/?|\\\u4e00-\u9fa5]/g ; for ( let i = 0 ; i < contentCharCode . length ; i ++ ) { let matchs = content [ i ] . match ( regex ) ; if ( matchs && matchs . length > 0 ) { contentCharCode [ i ] ^= result . key . charCodeAt ( index ) ; ch = String . fromCharCode ( contentCharCode [ i ] ) ; matchs = ch . match ( regex ) ; if ( matchs && matchs . length ) { } else { contentCharCode [ i ] ^= result . key . charCodeAt ( index ) ; } index ++ ; if ( index >= result . key . length ) { index = 0 ; } } else { } } let newContent = "" ; for ( let i = 0 ; i < contentCharCode . length ; i ++ ) { newContent += String . fromCharCode ( contentCharCode [ i ] ) ; } return newContent ; } else { if ( CC_DEBUG ) cc . error ( BitEncrypt . logTag , `encode/decode error content : ${ content } key : ${ key }` ) ; return content ; } } private _check ( content , key ) { if ( content && content . length > 0 ) { if ( key && key . length > 0 ) { return { isOK : true , key : key } ; } else { if ( this . encryptKey && this . encryptKey . length > 0 ) { return { isOK : true , key : this . encryptKey } ; } else { return { isOK : false , key : key } ; } } } else { return { isOK : false , key : key } ; } } } export let BitEncrypt = new _BitEncrypt ( ) ;