What is the difference between php and go?
This article mainly explains "what is the difference between php and go?". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the difference between php and go?"
Bitwise XOR of PHP
The ASCII value of echo "'Y' is:". Ord ('Y'). The ASCII value of PHP_EOL;echo "8 is:". Ord (8). The ASCII value of PHP_EOL;echo "8' is:". Ord ('8'). PHP_EOL;echo "'Y' ^ 8 =". ('Y' ^ 8). PHP_EOL; / / 8echo "'Y' + 8 =". ('Y' + 8). PHP_EOL; / / 8echo "Y' ^'8' =". ('Y' ^'8'). PHP_EOL; / / aecho "89 ^ 8 =". (89 ^ 8). PHP_EOL; / / 81echo "'89'^ 8 =". ('89'^ 8). PHP_EOL / / 8x parsing / / Y ascii 89 ^'8' ascii 56max / 89 ^ 8 = 1011001ax / ^ 000000A / = 1010001 = 64 + 16 + 4 + 1 = 81max / 89 ^ 56 = 1011001Accord / ^ 0111000pm / = 1100001 = 64 + 32 + 1 = 97 = a # the ASCII value of result'Y' is: 568' ASCII value is 'Y' + 8 = 8 years Y'^'8' = a89 ^ 8 = 81'89 ^ 8 = 81
When php is a non-numeric string and integer operation, the value is 0
Bitwise XOR of Go
Func main () {fmt.Println ("'Y' ^ 8 =",'Y' ^ 8) fmt.Println ("'Y' ^'8' =",'Y' ^'8') fmt.Println ("89 ^ 8 =", 89 ^ 8)} # result'Y' ^ 8 = 81 ^ Y' ^ 8' = 9789 ^ 8 = 81
Go is still relatively rigorous, converting rune to corresponding ascii code values for operation.
An encryption and decryption algorithm commonly used on the extended network PHP implements / / encryption function function encryptOp ($string) {$string = str_replace ('','+', $string); / / 2019-9-8 replace the space with the + sign at 16:36:12, and the + sign becomes a space during transmission $encryptKey = md5 (rand (0, 32000)); / / key $init = 0 for encryption; / / initialization variable length $tmp =''; $strLen = strlen ($string); / / length of string to be encrypted $encryptKeyLen = strlen ($encryptKey); / / length of encrypted key for ($index = 0; $index < $strLen; $index++) {$init = $init = $encryptKeyLen? 0: $init / / if $init = the length of $encryptKey, the $init zeroing / / $tmp string is added at the end, with the first bit being the $init bit of $encryptKey, and / / the second bit being the exclusive OR of the $index bit of $string and the $init bit of $encryptKey. Then $init = $init + 1$ tmp. = $encryptKey [$init]. ($string [$index] ^ $encryptKey [$init++]);} / / returns the result of base65 encoding of the value returned by the passportKeyOp () function return base64_encode (passportKeyOp ($tmp));} / / key handler function passportKeyOp ($string) {$encrypt_key = 'abcdefghijkl'; $encryptKey = md5 ($encrypt_key); / / encrypted key $init = 0; $tmp ='; $len = strlen ($string); $encryptKeyLen = strlen ($encryptKey) For ($index = 0; $index < $len; $index++) {$init = $init = = $encryptKeyLen? 0: $init; $tmp. = $string [$index] ^ $encryptKey [$init++];} return $tmp;} / / decryption function function decryptOp ($string) {$string = passportKeyOp (base64_decode ($string)); $tmp ='; $len = strlen ($string); for ($index = 0; $index < $len) $index++) {if (! isset ($string [$index]) | |! isset ($string [$index+ 1]) {return false;} $tmp. = $string [$index] ^ $string [+ + $index];} return $tmp;} $id = "123456"; $idStr = encryptOp ($id); echo $idStr. PHP_EOL;echo decryptOp ($idStr). PHP_EOL GO implements package mainimport ("crypto/md5"encoding/base64"fmt"math/rand"strconv"strings"time") func Md5 (str string) string {if str = = "" {return ""} init: = md5.New () init.Write ([] byte ") (str) return fmt.Sprintf ("x" Init.Sum (nil)} func MtRand (min, max int64) int64 {r: = rand.New (rand.NewSource (time.Now (). UnixNano ()) return r.Int63n (max-min+1) + min} func encryptOp (str string) string {encryptKey: = strconv.Itoa (int (MtRand (0)) 32000)) init: = 0 tmp: = "" strPlus: = [] rune (str) strLen: = len (strPlus) encryptKeyPlus: = [] rune (encryptKey) encryptKeyLen: = len (encryptKeyPlus) for index: = 0 Index < strLen Index++ {if init = = encryptKeyLen {init = 0} strInt: = int (strPlus [index]) encryptKeyInt: = int (string) tmp + = string (rune (strInt ^ encryptKeyInt)) init++} Sign: = passportKeyOp (tmp) sEnc: = base64.StdEncoding.EncodeToString ([] byte (sign)) return sEnc} func passportKeyOp (str string) string {key: = "abcdefghijkl" encryptKey: = Md5 (key) / / encrypted key init: = 0 result: = "" strPlus: = [] rune (str) strLen: = len (strPlus) encryptKeyPlus: = [] rune (encryptKey) encryptKeyLen: = len (encryptKeyPlus) for index: = 0 Index < strLen Index++ {if init = = encryptKeyLen {init = 0} result + = string (rune (int) ^ int) init++} return result} func decryptOp (str string) string {/ / replace the space with the + sign The + sign becomes a space str = strings.ReplaceAll (str, "", "+") sDec, _: = base64.StdEncoding.DecodeString (str) str = passportKeyOp (string (sDec)) result: = "" strPlus: = [] rune (str) strLen: = len (strPlus) for index: = 0 Index < strLen Index++ {result + = string (rune (int) ^ int) index++} return result} func main () {id: = "123456" idStr: = encryptOp (id) fmt.Println ("idStr =", idStr) fmt.Println ("id =", decryptOp (idStr))} Thank you for your reading The above is the content of "what is the difference between php and go?". After the study of this article, I believe you have a deeper understanding of the difference between php and go, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!