Simple Javascript encrypt, PHP decrypt with shared secret key

后端 未结 5 923
余生分开走
余生分开走 2020-12-09 04:24

This is not about security. It is also not to make it hard to break. I\'m looking for a simple algorithm to change a string (a url) in a way it does not resemble the origina

5条回答
  •  一整个雨季
    2020-12-09 05:24

    If it's not about security, and not about making it hard to break, then how about ROT-13?

    //+ Jonas Raoni Soares Silva
    //@ http://jsfromhell.com/string/rot13 [rev. #1]
    
    String.prototype.rot13 = function(){
        return this.replace(/[a-zA-Z]/g, function(c){
            return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
        });
    };
    
    ...
    
    var s = "My String";
    
    var enc = s.rot13();  // encrypted value in enc
    

    PHP has a native function, str_rot13: http://php.net/manual/en/function.str-rot13.php

    $decrypted = str_rot13($_GET['whatever']);
    

提交回复
热议问题