题解 | #字符串加解密#

字符串加解密

http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a

const line1 = readline()
const line2 = readline()

const ruleFun = (num, flag) => {
    // 加密
    if(flag){
        if(num === 57){
            return num - 9
        }else if(num >= 48 && num <= 56){
            return num + 1
        }else if(num >= 65 && num <= 89){
            return num + 33
        }else if(num >= 97 && num <= 121){
            return num - 31
        }else if(num === 90){
            return num + 7
        }else if(num === 122){
            return num - 57
        }
    }else{
        if(num === 48){
            return num + 9
        }else if(num >= 49 && num <= 57){
            return num - 1
        }else if(num >= 66 && num <= 90){
            return num + 31
        }else if(num >= 98 && num <= 122){
            return num - 33
        }else if(num === 65){
            return num + 57
        }else if(num === 97){
            return num - 7
        }
    }
    return num
}

const passwordFun = (str, flag) => {
    const LEN = str.length
    let res = ''
    for(let i = 0; i < LEN; i++){
        res += String.fromCharCode(ruleFun(str[i].charCodeAt(),flag))
    }
    console.log(res)
}
passwordFun(line1,1)
passwordFun(line2,0)

全部评论

相关推荐

09-29 17:44
已编辑
蔚来_测(准入职员工)
//鲨鱼辣椒:见不了了我实习了四个月上周再投筛选了一天就给我挂了
点赞 评论 收藏
分享
2 收藏 评论
分享
牛客网
牛客企业服务