Skip to content

I change salt but it not working #1

Description

@namnguyen2091

Please see my changed code and let me know what i'm wrong?
I want to change salt and alpha_map.
I try with paragraph but enter characters are lost, I dont want this.

function encode_str($str) {
    $encoded    = '';
    **$alpha_map = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];**
    $str        = ''.$str;
    $len        = strlen($str);
    $ascii_arr  = [];
    **$salt       = 1505;//rand(100, (999 - 255));**
    echo $salt;
    
    for ($x = 0; $x < $len; $x++) {
        $ascii_arr[$x] = (rand(1, 9) * 1000) + ($salt + ord($str[$x]));
    }
    
    $enc        = implode('', $ascii_arr) . $salt;
    $enc_len    = strlen($enc);
    
    for ($x = 0; $x < $enc_len; $x++) {
        if (array_key_exists($enc[$x], $alpha_map)) {
            $encoded .= $alpha_map[$enc[$x]];
        } else {
            $encoded .= $enc[$x];
        }
    }
    
    return strtolower($encoded);
}
function decode_str($str) {
    $str = strtoupper($str);
    $unit_size = 4;
    $alphatonum = function($s) {
        $alpha_map = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
        $l = strlen($s);
        $s_ = '';
        for ($x = 0; $x < $l; $x++) {
            $pos = array_search($s[$x], $alpha_map);
            $s_ .= in_array($s[$x], $alpha_map) ? array_search($s[$x], $alpha_map) : $s[$x];
        }
        return $s_;
    };
    
    $decoded    = '';
    **$salt       = $alphatonum(substr($str, -4));     
    $data       = $alphatonum(substr($str, 0, strlen($str) - 4));**
    
    $loop       = strlen($data) / $unit_size;
    $unit_arr   = [];
    for ($x = 0; $x < $loop; $x++) {
        $unit = substr($data, $x * $unit_size, $unit_size);
        
        **$ascii_ = ($unit % 10000) - $salt;**
        $decoded .= chr($ascii_);
    }
    
    return $decoded;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions