Table of Contents
php-simple symmetric encryption algorithm and conversion function between string and hexadecimal, php-hex
Home Backend Development PHP Tutorial php-simple symmetric encryption algorithm and conversion function between string and hexadecimal, php-hexadecimal_PHP tutorial

php-simple symmetric encryption algorithm and conversion function between string and hexadecimal, php-hexadecimal_PHP tutorial

Jul 13, 2016 am 09:59 AM
hexadecimal

php-simple symmetric encryption algorithm and conversion function between string and hexadecimal, php-hex

/**
* Encryption of simple symmetric encryption algorithm
* @param String $string The string to be encrypted
* @param String $skey Encryption EKY
* @return String
*/
function encode($string = '', $skey = 'textphp') {
$skey = str_split(base64_encode($skey));
$strArr = str_split(base64_encode($string));
$strCount = count($strArr);
foreach ($skey as $key => $value) {
$key < $strCount && $strArr[$key].=$value;
 }
 return str_replace('=', 'O0O0O', join('', $strArr));
}

/**
* Decryption of simple symmetric encryption algorithm
* @param String $string The string to be decrypted
* @param String $skey Decryption KEY
* @return String
*/
function decode($string = '', $skey = 'textphp') {
 $skey = str_split(base64_encode($skey));
 $ strArr = str_split(str_replace('O0O0O', '=', $string), 2);
$strCount = count($strArr);
foreach ($skey as $key => $value) {
  $key < $strCount && $strArr[$key][1] === $value && $strArr[$key] = $strArr[$key][0];
  }
   return base64_decode(join('', $strArr));
}

//Convert the string to hexadecimal
function str2hex($str, $encoded = 'GBK') {
$hex = '';
if ($encoded == 'GBK' ) {
  $str = mb_convert_encoding($str, 'GBK', 'UTF-8');
  }
 for ($i = 0, $length = mb_strlen($str); $i < ; $length; $i ) {
  $hex .= dechex(ord($str{$i}));
 }
 return $hex;
}

//Convert hexadecimal to string
function hex2str($hex, $encoded = 'GBK') {
 $str = '';
 $arr = str_split($hex, 2 );
foreach ($arr as $bit) {
$str .= chr(hexdec($bit));
}
if ($encoded == 'GBK') {
  $str = mb_convert_encoding($str, 'UTF-8', 'GBK');
  }
  return $str;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/976448.htmlTechArticlephp-simple symmetric encryption algorithm and conversion function between string and hexadecimal, php-ten Hexadecimal/** * Encryption of simple symmetric encryption algorithm* @param String $string The string that needs to be encrypted...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to convert binary to hexadecimal using C language? How to convert binary to hexadecimal using C language? Sep 01, 2023 pm 06:57 PM

Binary numbers are represented by 1s and 0s. The 16-bit hexadecimal number system is {0,1,2,3…..9,A(10),B(11),…F(15)} in order to convert from binary representation to hexadecimal Represents that the bit string ID is grouped into 4-bit chunks, called nibbles starting from the least significant side. Each block is replaced with the corresponding hexadecimal number. Let us see an example to get a clear understanding of hexadecimal and binary number representation. 001111100101101100011101 3 E 5 B&nb

How to convert hex encoding e8 af 9a to Chinese in PHP? How to convert hex encoding e8 af 9a to Chinese in PHP? Feb 27, 2024 pm 04:09 PM

Title: Example of converting hexadecimal encoding to Chinese characters in PHP In PHP, if we need to convert hexadecimal encoding to Chinese characters, we can do it by using the hex2bin() function. A specific code example is given below:

Hexadecimal to octal conversion program in C program Hexadecimal to octal conversion program in C program Aug 29, 2023 pm 02:17 PM

We get a hexadecimal number as a string; the task is to convert it to octal. To convert a hexadecimal number to octal number, we have to - find the binary equivalent of the hexadecimal number. Convert binary number to octal number. What is hexadecimal? Hexadecimal numbers are numbers based on base 16. Numbers range from 0 to 9. Starting from 10, numbers are represented as A, which represents 10, B represents 11, C represents 12, D represents 13, and E. stands for 14, F stands for 15. To convert a hexadecimal number to binary, each number is converted to a 4-digit binary number. What is octal? Octal in computers is represented in base 8, i.e. octal numbers from 0 to 7 are represented by three binary digits or three composed of binary digits. What we have to do is like we have

Binary to hexadecimal Binary to hexadecimal Jan 16, 2024 pm 04:15 PM

The way to convert a binary number to a hexadecimal number is to group the binary number into groups of 4 digits and convert each group into the corresponding hexadecimal number.

Decoding and encoding hexadecimal numbers using Python Decoding and encoding hexadecimal numbers using Python Aug 19, 2023 pm 02:09 PM

In this article, we will learn how to decode and encode hexadecimal numbers using Python. Methods used Using the binascii module Using the base64 module Method 1: Using the Binascii module In the binascii module, there are several methods to convert between binary and different ASCII-encoded binary representations. If you just need to encode or decode a raw string of hexadecimal digits, use the binascii module. Algorithm (Steps) Following are the algorithms/steps to perform the required task. −Use the import keyword to import the binascii module. Create a variable to store the input byte string. b2a_ using binascii module

Check if a string represents a hexadecimal number Check if a string represents a hexadecimal number Sep 25, 2023 am 11:45 AM

In computer science, hexadecimal is a 16-based number system. It uses 16 different symbols, including the ten decimal digits 0 to 9 and the six letters A, B, C, D, E and F to represent numbers from 0 to 15. In this article, we will discuss how to check if a string represents a hexadecimal number. Problem Statement Given a string, the task is to check if it represents a valid hexadecimal number. Method We can solve this problem by iterating the characters in the string and checking if they belong to a valid hex character set. Valid hexadecimal characters are numbers from 0 to 9 and letters from A to F (regardless of uppercase or lowercase). If all characters in a string belong to this character set, then the string represents a valid

Java program example showing how to use hexadecimal Java program example showing how to use hexadecimal Sep 10, 2023 pm 11:37 PM

Here,theusageofHexadecimalshallbedemonstratedthroughtheJavaProgram.LetusgetacquaintedwiththetermHexadecimalbeforeseeingaJavaprogram.TheHexadecimalisatypeofnumbersystemthathasabasevalueof16.Thereare16symbolsrepresentinghexadecimalnumbers.Thesesymbolso

Convert hexadecimal to octal in Java? Convert hexadecimal to octal in Java? Aug 19, 2023 pm 01:37 PM

OctalNumber−Octalnumberisalsooneofthenumbersystemsavailable.Theoctalnumberisrepresentedwith8digitswhichisfrom0to7(0,1,2,3...7).TheOctalnumbersareexpressedasbase-8inthenumeralsystem.HexadecimalNumber−Hexadecimalnumberisalsooneofthenumbersystemsavailab

See all articles