Code Monkey home page Code Monkey logo

lrc4's Introduction

lrc4

travis-ci status

Native Lua/LuaJIT RC4 stream cipher library

Lua Compatibility

Version Module Dependencies Remark
Lua 5.2 bit32
Lua 5.3 bit32 bit32 has been deprecated
LuaJIT 2.0/2.1 ffi, bit ffi C struct optimized

Usage

local rc4 = require("rc4")
local key = "my_secret"

-- generate keystream
local rc4_ks_server = rc4(key)
local rc4_ks_client = rc4(key)

-- server encrypts messages
local msg_from_server_1 = "Hello"
local msg_from_server_2 = "This is SERVER"
local encrypted_msg_1 = rc4_ks_server(msg_from_server_1)
local encrypted_msg_2 = rc4_ks_server(msg_from_server_2) 

-- client decrypts messages one after another
local decrypted_msg_1 = rc4_ks_client(encrypted_msg_1)
assert(msg_from_server_1 == decrypted_msg_1)
local decrypted_msg_2 = rc4_ks_client(encrypted_msg_2)
assert(msg_from_server_2 == decrypted_msg_2)

Test and Benchmark

# Lua 5.2.4
$ lua52 rc4.lua
RC4 keygen test    10.250 sec (100000 times, #key 8)
RC4 crypt test     68.980 sec (100000 times, #key 8, #input 512)

# Lua 5.3.1
$ lua53 rc4.lua
RC4 keygen test    10.280 sec (100000 times, #key 8)
RC4 crypt test     72.310 sec (100000 times, #key 8, #input 512)

# LuaJIT 2.0.4
$ luajit-2.0.4 rc4.lua
RC4 keygen test     0.310 sec (100000 times, #key 8)
RC4 crypt test      0.800 sec (100000 times, #key 8, #input 512)

# LuaJIT 2.1.0 beta1
$ luajit-2.1.0-beta1 rc4.lua
RC4 keygen test     0.280 sec (100000 times, #key 8)
RC4 crypt test      0.740 sec (100000 times, #key 8, #input 512)

License

Copyright (c) 2015 Cheyi Lin. MIT licensed. See LICENSE for details.

lrc4's People

Contributors

cheyilin avatar

Watchers

James Cloos avatar  avatar

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.