XXTEA encryption algorithm library for PHP.

Overview

XXTEA for PHP

XXTEA logo

Build Status Packagist Packagist Download License

Introduction

XXTEA is a fast and secure encryption algorithm. This is a XXTEA library for PHP.

It is different from the original XXTEA encryption algorithm. It encrypts and decrypts string instead of uint32 array, and the key is also string.

Installation

Download the xxtea.php, and put it in your develepment directory.

Usage

<?php
    require_once("xxtea.php");
    $str = "Hello World! 你好,中国!";
    $key = "1234567890";
    $encrypt_data = xxtea_encrypt($str, $key);
    $decrypt_data = xxtea_decrypt($encrypt_data, $key);
    if ($str == $decrypt_data) {
        echo "success!";
    } else {
        echo "fail!";
    }
?>
Comments
  • Cannot decrypt data encrypted in Java

    Cannot decrypt data encrypted in Java

    java code: byte b[] = encrypt(plain.getBytes(charset), ByteFormat.hexToBytes(hexKey)); return ByteFormat.toHex(b);

    Encrypted data is not the same as PHP.

    opened by hepeichun 4
  • Incompatibility with Arduino XXTEA

    Incompatibility with Arduino XXTEA

    This library seems incompatible with Arduino XXTEA. The application was to send an encrypted data from Arduino via POST request and decrypt it in PHP. Arduino XXTEA used

    The two libraries decode in different ways it seems.

    Look at the picture below, you see how the ecrypted string in Arduino is d49baa5e4b9b6ee6c8cf5ab0a61baa7a But the encrypted string in PHP xxtea is a bounch of awful stuff: ,„'—ÍÌIˆ(¦HLìF0do Look at the screenshot, on the right there is the Arduino serial monitor encrypting with its XXTEA and on the left PHP encrypting with your XXTEA image

    Maybe converting those buch of waful stuff from HEX to string I can have a result.

    opened by pedros89 4
  • Encryption with XXTEA/PHP different from XXTEA/JavaScript

    Encryption with XXTEA/PHP different from XXTEA/JavaScript

    Here is are some results with XXTEA/PHP:

    text:    This is an example. !@#$%^&*(){}[]:;
    key:     8GmZWww5T97jb39W
    encrypt: ZB3oHyOnV+jeZlS4JzQYxwiToxy0NYbcV7YN8wPDHsNLTjxJGPr+5w==
    decrypt: This is an example. !@#$%^&*(){}[]:;
    

    Encryption does not match the results for XXTEA/JavaScript:

    text:    This is an example. !@#$%^&*(){}[]:;
    key:     8GmZWww5T97jb39W
    encrypt: BPAOskr9QeOE9S2gtKrArurP5RtjM+5GzQF6gLB4BKi+HAJV
    decrypt: This is an example. !@#$%^&*(){}[]:;
    
    opened by David263 1
  • Bug with >> on some php version

    Bug with >> on some php version

    Hi, i have a fix to suggest : In the function mx(), in my server, i had an issue with right byte shifting in $y >> 3 because it returned negative values. For fixting it : (from http://stackoverflow.com/questions/2642026/php-equivalent-javascript-shift-right-with-zero-fill-bitwise-operators )

    private static function rightShift($x, $c)
              {
                  $x = intval ($x); // Because 13.5 >> 0 returns 13. We follow.
                  $nmaxBits = PHP_INT_SIZE * 8;
                  $c %= $nmaxBits;
                  if ($c)
                      return $x >> $c & ~ (-1 << $nmaxBits - $c);
                  else
                      return $x;
              }
    

    then replace eveywhere you use x << y

    opened by emeric0101 3
  • performance issue

    performance issue

    This is my local test, which data_x represents how much megabits to be encrypt. I generated from 1 to 100 megabits to data directory, below is some test results. It's used huge memory and time to encrypt data.

    test tools https://github.com/Svish/TimerPHP /my/path/to/test_xxtea/test_xxtea.php() │ │ 78.502 s │ 6.58 KiB, 1.14 GiB │ ├ test_encrypt() │ │ │ │ 78.502 s │ │ 5.86 KiB, 1.14 GiB │ │ │ ├ test_encrypt(data/data_10) │ │ │ │ │ │ 12.831 s │ │ │ 1.44 KiB, 855.50 MiB │ │ ─┘ │ │ │ ├ test_encrypt(data/data_11) │ │ │ │ │ │ 14.563 s │ │ │ 160.00 B, 934.50 MiB │ │ ─┘ │ │ │ ├ test_encrypt(data/data_12) │ │ │ │ │ │ 15.647 s │ │ │ 144.00 B, 1013.50 MiB │ │ ─┘ │ │ │ ├ test_encrypt(data/data_13) │ │ │ │ │ │ 16.984 s │ │ │ 144.00 B, 1.07 GiB │ │ ─┘ │ │ │ ├ test_encrypt(data/data_14) │ │ │ │ │ │ 18.477 s │ │ │ 144.00 B, 1.14 GiB │ │ ─┘ │ ─┘

    test_xxtea_script.php

    <?php
    include 'Xxtea.class.php';
    include 'Timer.php';
    
    function p($message = '', $tag = 'debug') {
        echo '['. $tag .']'. " ". $message ."\n";
    }
    
    function generateData($meta=1)
    {
        // 1024
        $str = str_repeat(str_repeat('y', pow(2, 10)), $meta*1024);
        $file_name = 'data/data_'.$meta;
        file_put_contents($file_name, $str);
        p("generate ".$meta." M data to ".$file_name, 'generate data');
        unset($str);
    }
    
    function test_encrypt($start, $end) 
    {
        Timer::start('test_encrypt');
        for($i = $start; $i < $end; $i++)
        {        
            $file_name = "data/data_".$i;
            p($file_name, 'before encrypt');
            Timer::start("test_encrypt", [$file_name]);      
            $encrypt_data = null;    
            if (file_exists($file_name))
            {
                $encrypt_data = xxtea_encrypt(file_get_contents($file_name));
                file_put_contents("data_enrypt/data_".$i."_enrypted", $encrypt_data);
            }
            unset($encrypt_data);
            p($file_name, 'after encrypt');
            // Sub section stuff
            Timer::stop();
        }
    }
    $start = 10;
    $end = 15;
    Timer::start($_SERVER['PHP_SELF']);
    test_encrypt($start, $end);
    Timer::stop();
    echo $result = Timer::result();
    file_put_contents("result_".$start."_".$end.".txt", $result);
    
    
    opened by arist1213 1
Releases(v1.0.2)
Owner
xxtea
XXTEA encryption arithmetic library
xxtea
Implementation of the Token Bucket algorithm in PHP.

Token Bucket This is a threadsafe implementation of the Token Bucket algorithm in PHP. You can use a token bucket to limit an usage rate for a resourc

null 477 Jan 7, 2023
PHP implementation of Rapid Automatic Keyword Exraction algorithm (RAKE) for extracting multi-word phrases from text

PHP implementation of Rapid Automatic Keyword Exraction algorithm (RAKE) for extracting multi-word phrases from text.

Assisted Mindfulness 7 Oct 19, 2022
Laravel package to generate sweepstakes using the Round Robin algorithm

Laravel package to generate sweepstakes using the Round Robin algorithm. Supports any number of teams, as long as they are greater than a minimum value specified in the configuration file. Built with Laravel Collections for better handling of arrays.

TonyStore 6 Aug 3, 2022
This package implements 0-1 Knapsack Problem algorithm i.e. allows to find the best way to fill a knapsack of a specified volume with items of a certain volume and value.

This package implements "0-1 Knapsack Problem" algorithm i.e. allows to find the best way to fill a knapsack of a specified volume with items of a certain volume and value.

Alexander Makarov 9 Sep 8, 2022
Dobren Dragojević 6 Jun 11, 2023
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP

Lodash-PHP Lodash-PHP is a port of the Lodash JS library to PHP. It is a set of easy to use utility functions for everyday PHP projects. Lodash-PHP tr

Lodash PHP 474 Dec 31, 2022
PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP language

php-text-analysis PHP Text Analysis is a library for performing Information Retrieval (IR) and Natural Language Processing (NLP) tasks using the PHP l

null 464 Dec 28, 2022
php-echarts is a php library for the echarts 5.0.

php-echarts 一款支持Apache EChart5.0+图表的php开发库 优先ThinkPHP5/6的开发及测试。 Apache EChart5.0已经最新发布,在视觉效果、动画效果和大数据展示方面已经远超之前的版本; 故不考虑EChart5.0之前版本的兼容问题;建议直接尝试5.0+

youyiio 5 Aug 15, 2022
Minimalist PHP frame for Core-Library, for Developing PHP application that gives you the full control of your application.

LazyPHP lightweight Pre-Made Frame for Core-library Install Run the below command in your terminal $ composer create-project ryzen/lazyphp my-first-pr

Ry-Zen 7 Aug 21, 2022
Gettext is a PHP (^7.2) library to import/export/edit gettext from PO, MO, PHP, JS files, etc.

Gettext Note: this is the documentation of the new 5.x version. Go to 4.x branch if you're looking for the old 4.x version Created by Oscar Otero http

Gettext 651 Dec 29, 2022
Columnar analytics for PHP - a pure PHP library to read and write simple columnar files in a performant way.

Columnar Analytics (in pure PHP) On GitHub: https://github.com/envoymediagroup/columna About the project What does it do? This library allows you to w

Envoy Media Group 2 Sep 26, 2022
:date: The VObject library for PHP allows you to easily parse and manipulate iCalendar and vCard objects

sabre/vobject The VObject library allows you to easily parse and manipulate iCalendar and vCard objects using PHP. The goal of the VObject library is

sabre.io 532 Dec 25, 2022
Small convention based CQRS library for PHP

LiteCQRS for PHP Small naming-convention based CQRS library for PHP (loosely based on LiteCQRS for C#) that relies on the MessageBus, Command, EventSo

Benjamin Eberlei 560 Nov 20, 2022
Experimental library for forking PHP

Spork: PHP on a Fork <?php $manager = new Spork\ProcessManager(); $manager->fork(function() { // do something in another process! return 'Hel

Kris Wallsmith 588 Nov 20, 2022
Collection pipeline library for PHP

Knapsack Collection pipeline library for PHP Knapsack is a collection library for PHP >= 5.6 that implements most of the sequence operations proposed

Dušan Kasan 540 Dec 17, 2022
A PHP library to play with the Raspberry PI's GPIO pins

php-gpio php-gpio is a simple PHP library to play with the Raspberry PI's GPIO pins. It provides simple tools such as reading & writing to pins. [UPDA

Ronan Guilloux 266 Oct 17, 2022
PHP library for dealing with European VAT

ibericode/vat This is a simple PHP library to help you deal with Europe's VAT rules. Fetch VAT rates for any EU member state using ibericode/vat-rates

ibericode 389 Dec 31, 2022
iOS passbook library for PHP 5.4+

PHP PASSBOOK LIBRARY What is Passbook? Passbook is an application in iOS that allows users to store coupons, boarding passes, event tickets, store car

Eymen Gunay 256 Nov 17, 2022
Sslurp is a simple library which aims to make properly dealing with SSL in PHP suck less.

Sslurp v1.0 by Evan Coury Introduction Dealing with SSL properly in PHP is a pain in the ass and completely insecure by default. Sslurp aims to make i

Evan Coury 65 Oct 14, 2022