Giter VIP home page Giter VIP logo

dcode's Introduction

DCode

It's php extension for encrypt、 decrypt and gen qrcode, the en/decrypt implement algorithm of discuz authcode function, qrcode based on QR Code encoder.

QRcode

It's based on QR Code encoder, just use a simple api QRcode_encodeString, QRcode_encodeString8bit,QRcode_encodeData

dependencies

php5.4+
libpng

Usage

DCode::encrypt($src, $key = "THIS IS SHIT", $ckeylength = 8, $expire = 0);
DCode::decrypt($src, $key = "THIS IS SHIT", $ckeylength = 8);

/** 
* DCode::qrcode($str, $version = 0, $level = QR_ECLEVEL_L, $mode = QR_MODE_KANJI, $casesensitive = 0);
* @param $str;
* @param $version = 0;
* @param $level = QR_ECLEVEL_L;
* @param $model = QR_MODE_KANJI;
* @param $casesensitive = 0;
* @return string
*/
$filecontent = DCode::qrcode("HELLO");
file_put_contents("test.png", $filecontent);

/**
* DCode::qrcode8bit($str, $version = 0, $level = QR_ECLEVEL_L);
* @param $str;
* @param $version = 0;
* @param $level = QR_ECLEVEL_L;
* @return string
*/
$filecontent = DCode::qrcode8bit("HELLO WORLD");
file_put_contents("test1.png", $filecontent);

/**
* DCode::qrcodedata($sizeof, $data, $version = 0, $level = QR_ECLEVEL_L);
* @param $sizeof
* @param $data
* @param $version = 0;
* @param $level = QR_ECLEVEL_L;
* @return string
*/
$filecontent = DCode::qrcodedata(strlen("HELLO WORLD"), "HELLO WORLD");
file_put_contents("test2.png", $filecontent);

dcode_encrypt($src, $key = "THIS IS SHIT", $ckeylength = 8, $expire = 0);
dcode_decrypt($src, $key = "THIS IS SHIT", $ckeylength = 8);

$filecontent = dcode_qrcode("HELLO");
file_put_contents("test.png", $filecontent);

$filecontent = dcode_qrcode8bit("HELLO 8bit");
file_put_contents("test1.png", $filecontent);

$filecontent = dcode_qrcodedata(strlen("HELLO 8bit"), "HELLO 8bit");
file_put_contents("test2.png", $filecontent);

Install

git clone [email protected]:outman/dcode.git
cd dcode
phpize
./configure
make && make test
make install

PHP.ini

extension=dcode.so

Time test code

dcode.php
<?php
for ($i = 0; $i < 100000; $i ++) {
    $code = DCode::encrypt($i);
    DCode::decrypt($code);
}

authcode.php

<?php
function authcode(.............

for ($i = 0; $i < 100000; $i ++) {
    $code = authcode($i, "ENCODE");
    authcode($code);
}

Time test result

100000 times en/decrypt code
time php authcode.php   90.37s user 0.18s system 99% cpu 1:30.59 total
time php dcode.php   2.19s user 0.08s system 99% cpu 2.278 total

5000000 times decode.php
116.53s user 4.79s system 92% cpu 2:11.73 total

LICENSE

MIT

Error with Ubuntu

png_create_write_struct in Unknown on line 0 on ubuntu 14
FIX:
  • create soft link
sudo ln -s /usr/lib/x86_64-linux-gnu/libpng12.so /usr/lib/x86_64-linux-gnu/libpng.so
  • edit Makefile INCLUDES section, append -L/usr/lib/x86_64-linux-gnu -lpng to INCLUDES

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.