String XOR Ruby Extension
fast_xor
is a simple extension which provides fast in-place String XOR functions (suitable for cryptography).
How do you use it?
require 'xor'
# two-argument version
a, b = 'a string', 'another string'
a.xor!(b)
a == "\000N\034\000\032\f\034G"
# three-argument version
a, b, c = 'a string', 'another string', 'yet another string'
a.xor!(b, c)
a == "y+h {bs3"
How fast is “Fast”?
On my computer, about 1,000x faster than pure Ruby (your mileage my vary):
$ ruby test/benchmark.rb
user system total real
Ruby: 2.070000 0.930000 3.000000 ( 3.004088)
C : 0.010000 0.000000 0.010000 ( 0.003045)
- Author
-
Steve Sloan ([email protected])
- Website
- Copyright
-
Copyright © 2009 Steve Sloan
- License
-
MIT