Module: Xorcist
- Defined in:
- lib/xorcist.rb,
lib/xorcist/version.rb,
lib/xorcist/refinements.rb,
lib/xorcist/string_methods.rb,
ext/xorcist/xorcist.c
Defined Under Namespace
Modules: Refinements, StringMethods
Constant Summary
collapse
- VERSION =
'1.0.1'
Class Method Summary
collapse
Class Method Details
.xor(x, y) ⇒ Object
12
13
14
|
# File 'lib/xorcist.rb', line 12
def xor(x, y)
xor!(x.dup, y)
end
|
.xor!(x, y) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'ext/xorcist/xorcist.c', line 9
VALUE xor_in_place(VALUE self, VALUE x, VALUE y) {
const char *src = 0;
char *dest = 0;
size_t len;
size_t y_len;
rb_str_modify(x);
dest = RSTRING_PTR(x);
len = RSTRING_LEN(x);
src = RSTRING_PTR(y);
y_len = RSTRING_LEN(y);
if (y_len < len) {
len = y_len;
}
for (; len--; ++dest, ++src) {
*dest ^= *src;
}
return x;
}
|