<?php
error_reporting(0);
header('Content-Type: application/json');

if($_POST['fun'] == 'getSetStr'){
    $data = $_POST['data'];
    $setStr = lockSet($data);
    echo json_encode([
        'code' => 200,
        'data' => $setStr,
        'msg' => 'success'
    ]);
}

function lockSet($txt)
{
    $key = 'lovestu.com';
    $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+";
    $txt = base64_encode($txt);
    $tmp = '';
    $ch = $chars[rand(0, 63)];
    $nh = strpos($chars, $ch);
    $mdKey = md5($key . $ch);
    $mdKey = substr($mdKey, $nh % 8, $nh % 8 + 7);
    $tmp .= $ch;
    $k = 0;
    for ($i = 0; $i < strlen($txt); $i++) {
        $k = $k == strlen($mdKey) ? 0 : $k;
        $j = strpos($chars, $txt[$i]) + $nh + ord($mdKey[$k++]);
        while ($j < 0) {
            $j += 64;
        }
        $tmp .= $chars[$j % 64];
    }
    return urlencode($tmp);
}