《算法还原 - 练习》js 与 py 互转

原始

function eee(e, t) {
    for (var r = "", n = 0, a = 0; a < t.length; a++) {
        var o = e.charCodeAt(n % e.length)
          , i = t.charCodeAt(a)
          , s = i;
        i >= 65 && i <= 90 && (o >= 65 && o <= 90 && (s = (o - 65 + (i - 65)) % 26 + 65),
        o >= 97 && o <= 122 && (s = (o - 97 + (i - 65)) % 26 + 65),
        n++),
        i >= 97 && i <= 122 && (o >= 65 && o <= 90 && (s = (o - 65 + (i - 97)) % 26 + 97),
        o >= 97 && o <= 122 && (s = (o - 97 + (i - 97)) % 26 + 97),
        n++),
        r += String.fromCharCode(s)
    }

    return r

}

var ok = eee("twsQxLjHavDVuLPNprkFyuVowxfEZdkAYYyBqbnMN", "JTdCJTIyaWM0ElMjI5Mzc0MjI2MjglMjIlMkMlMjJjYXB0Y2hhQ29kZSUyMiUzQSUyMjE4NTIlMjIlMkMlMjJ0ZXJtaW5hbCUyMBJTIyNzg5ZXlzLmNvbSUyMiUyQyUyMmZpbmdlck9TTW9kZWwlMjIlM0ElMjJFZGdlKzExNi4wLjAuMCslN0MrQW5kcm9pZCs4LjAuMCUyMiUyQyUyMnp0c0xhbmclMjIlM0ElMjJ6aCUyMiU3RCU3RA==")

console.log(ok=="CPvSGERfaRP0ZfXyV5Bqm0RhC2HxciRnHoWkKjKkZkLJO0R2dzG29hKBByHlPtBHHnDtJ4LNDzIgNpLnWlKhH0ANKgmJ5axUKvXKQTDbItr5OKaqVrLpwGQvRmTbAySwKnPqoyqeyc9JQH9tGWroHdTaZ0TcWoHZUUziPdDaXi4uJhBkNPeyG0IjGT5vlt9pUFn4FuPhBTEdKcPmMvZcLqz0c0vfznsmZvVeI0WbJuS6hCPbHcF3GPJ3IK==");

格式化

function eee(e, t) {
    for (var r = "", n = 0, a = 0; a < t.length; a++) {
        var o = e.charCodeAt(n % e.length);
        i = t.charCodeAt(a);
        s = i;

        if (i >= 65 && i <= 90) {
            if (o >= 65 && o <= 90) {
                s = (o - 65 + (i - 65)) % 26 + 65
            }
            if (o >= 97 && o <= 122) {
                s = (o - 97 + (i - 65)) % 26 + 65
            }
            n++
        }

        if (i >= 97 && i <= 122) {
            if (o >= 65 && o <= 90) {
                s = (o - 65 + (i - 97)) % 26 + 97
            }
            if (o >= 97 && o <= 122) {
                s = (o - 97 + (i - 97)) % 26 + 97
            }
            n++
        }
        r += String.fromCharCode(s)
    }
    return r
}

var ok = eee("twsQxLjHavDVuLPNprkFyuVowxfEZdkAYYyBqbnMN", "JTdCJTIyaWM0ElMjI5Mzc0MjI2MjglMjIlMkMlMjJjYXB0Y2hhQ29kZSUyMiUzQSUyMjE4NTIlMjIlMkMlMjJ0ZXJtaW5hbCUyMBJTIyNzg5ZXlzLmNvbSUyMiUyQyUyMmZpbmdlck9TTW9kZWwlMjIlM0ElMjJFZGdlKzExNi4wLjAuMCslN0MrQW5kcm9pZCs4LjAuMCUyMiUyQyUyMnp0c0xhbmclMjIlM0ElMjJ6aCUyMiU3RCU3RA==")
//console.log(ok);
console.log(ok == "CPvSGERfaRP0ZfXyV5Bqm0RhC2HxciRnHoWkKjKkZkLJO0R2dzG29hKBByHlPtBHHnDtJ4LNDzIgNpLnWlKhH0ANKgmJ5axUKvXKQTDbItr5OKaqVrLpwGQvRmTbAySwKnPqoyqeyc9JQH9tGWroHdTaZ0TcWoHZUUziPdDaXi4uJhBkNPeyG0IjGT5vlt9pUFn4FuPhBTEdKcPmMvZcLqz0c0vfznsmZvVeI0WbJuS6hCPbHcF3GPJ3IK==");

python


def eee(e, t):
    r = ""
    n = 0
    for a in range(len(t)):
        o = ord(e[n % len(e)])
        i = ord(t[a])
        s = i

        if i >= 65 and i <= 90:
            if o >= 65 and o <= 90:
                s = (o - 65 + (i - 65)) % 26 + 65
            if o >= 97 and o <= 122:
                s = (o - 97 + (i - 65)) % 26 + 65
            n = n + 1

        if i >= 97 and i <= 122:
            if o >= 65 and o <= 90:
                s = (o - 65 + (i - 97)) % 26 + 97
            if o >= 97 and o <= 122:
                s = (o - 97 + (i - 97)) % 26 + 97
            n = n + 1

        r = r + chr(s)
    return r

ok = eee("twsQxLjHavDVuLPNprkFyuVowxfEZdkAYYyBqbnMN", "JTdCJTIyaWM0ElMjI5Mzc0MjI2MjglMjIlMkMlMjJjYXB0Y2hhQ29kZSUyMiUzQSUyMjE4NTIlMjIlMkMlMjJ0ZXJtaW5hbCUyMBJTIyNzg5ZXlzLmNvbSUyMiUyQyUyMmZpbmdlck9TTW9kZWwlMjIlM0ElMjJFZGdlKzExNi4wLjAuMCslN0MrQW5kcm9pZCs4LjAuMCUyMiUyQyUyMnp0c0xhbmclMjIlM0ElMjJ6aCUyMiU3RCU3RA==")
# print(ok)
print(ok=="CPvSGERfaRP0ZfXyV5Bqm0RhC2HxciRnHoWkKjKkZkLJO0R2dzG29hKBByHlPtBHHnDtJ4LNDzIgNpLnWlKhH0ANKgmJ5axUKvXKQTDbItr5OKaqVrLpwGQvRmTbAySwKnPqoyqeyc9JQH9tGWroHdTaZ0TcWoHZUUziPdDaXi4uJhBkNPeyG0IjGT5vlt9pUFn4FuPhBTEdKcPmMvZcLqz0c0vfznsmZvVeI0WbJuS6hCPbHcF3GPJ3IK==")

你可能感兴趣的:(算法,javascript,python)