<commit_before># Xorcist :ghost:

[![Gem Version](https://badge.fury.io/rb/xorcist.svg)](http://badge.fury.io/rb/xorcist)
[![Build Status](https://travis-ci.org/fny/xorcist.svg?branch=master)](https://travis-ci.org/fny/xorcist)

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

## Usage

```ruby
require 'xorcist'

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

You can `include Xorcist` to expose its methods:

```ruby
require 'xorcist'
include Xorcist

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

Refinements on `String` are also available:

```ruby
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:

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

## Benchmarks

Disclaimer: these are run from my craptop. Run 'em yourself with `bin/benchmark`.

### 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
```
<commit_msg>Add note about string output encoding<commit_after># Xorcist :ghost:

[![Gem Version](https://badge.fury.io/rb/xorcist.svg)](http://badge.fury.io/rb/xorcist)
[![Build Status](https://travis-ci.org/fny/xorcist.svg?branch=master)](https://travis-ci.org/fny/xorcist)

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

## Usage

```ruby
require 'xorcist'

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

You can `include Xorcist` to expose its methods:

```ruby
require 'xorcist'
include Xorcist

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

Refinements on `String` are also available:

```ruby
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:

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

## Encodings

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

## Benchmarks

Disclaimer: these are run from my craptop. Run 'em yourself with `bin/benchmark`.

### 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
```

{'fraction_non_alphanumeric': 0.235874931431706, 'fraction_numerical': 0.04909489851892485, 'mean_word_length': 1.9340305711987127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4450430', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1293, 'n_words': 317}