Blazing-fast-cross-platform-monkey-patch-free string XOR
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
certs
checksums
ext/xorcist
lib
test
.editorconfig
.gitignore
.travis.yml
Gemfile
LICENSE.txt
README.md
Rakefile
xorcist.gemspec

README.md

Xorcist 👻

Gem Version Build Status

Note: The build is breaking due to a regression with refinements in JRuby 9.2. This isn't an issue for earlier versions of JRuby 9.0-9.1. I'll likely release a new version without support for refinements for broader compatibility, particularly since no one seems to use refinements.

Blazing-fast-cross-platform-monkey-patch-free string XOR. Yes, that means JRuby too.

Usage

require 'xorcist'

a, b = 'a', 'b'
Xorcist.xor(a, b) # => "\u0003"
a # => 'a'
Xorcist.xor!(a, b) # => "\u0003"
a # => "\u0003"
Xorcist.xor!(a.freeze, b) # => RuntimeError!

You can include Xorcist to expose its methods:

require 'xorcist'
include Xorcist

a, b = 'a', 'b'
xor(a, b)
xor!(a, b)

Refinements on String are also available:

require 'xorcist'
require 'xorcist/refinements'
using Xorcist::Refinements

a, b = 'a', 'b'
a.xor(b)
a.xor!(b)

You can also monkey patch String if you're into that:

require 'xorcist'
require 'xorcist/string_methods'
String.include(Xorcist::StringMethods)

Encodings

Note the precise encoding xor's output is undefined in the v1.0-1.x releases. In MRI xor! will return a string using your default encoding. With JRuby, xor! will return an ASCII-8BIT string.

Security

Xorcist is cryptographically signed. To be sure the gem you install hasn’t been tampered with:

Add my public key as a trusted certificate:

gem cert --add <(curl -Ls https://raw.github.com/fny/xorcist/master/certs/fny.pem)

Then install the gem:

gem install xorcist -P HighSecurity

Checksums for all versions are also included in the checksums directory.

Benchmarks

Disclaimer: these are run from my craptop. Run 'em yourself with bin/benchmark. You'll need to have benchmark-ips installed.

MRI 2.2.1

Calculating -------------------------------------
                ruby    26.378k i/100ms
             xorcist    73.291k i/100ms
-------------------------------------------------
                ruby    376.513k (± 0.5%) i/s -      1.899M
             xorcist      2.150M (± 3.9%) i/s -     10.774M

JRuby 1.7.19

Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
Calculating -------------------------------------
                ruby    31.795k i/100ms
             xorcist   118.084k i/100ms
-------------------------------------------------
                ruby    978.078k (±11.2%) i/s -      4.801M
             xorcist      3.897M (±14.1%) i/s -     19.012M

Installation

Add this line to your application's Gemfile:

gem 'xorcist'

And then execute:

$ bundle

Or install it yourself as:

$ gem install xorcist

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fny/xorcist. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Special Thanks To...