<commit_before>/**********************************************************\
|                                                          |
| xxtea.c                                                  |
|                                                          |
| XXTEA encryption algorithm library for Lua.              |
|                                                          |
| Encryption Algorithm Authors:                            |
|      <NAME>                                    |
|      <NAME>                                    |
|                                                          |
| Code Authors: <NAME> <<EMAIL>>                |
|               <NAME> <<EMAIL>>           |
| LastModified: Feb 8, 2016                                |
|                                                          |
\**********************************************************/

#include <ruby.h>
#if (RUBY_VERSION_MAJOR == 1) && (RUBY_VERSION_MINOR > 8) || (RUBY_VERSION_MAJOR > 1)
#include <ruby/encoding.h>
#endif
#include "xxtea.h"

VALUE rb_encrypt(VALUE mod, VALUE data, VALUE key) {
	unsigned char * result;
	VALUE retval;
	size_t data_len, out_len;

	Check_Type(data, T_STRING);
	Check_Type(key, T_STRING);

	data_len = RSTRING_LEN(data);

	result = xxtea_encrypt(RSTRING_PTR(data), data_len, RSTRING_PTR(key), &out_len);

	retval = rb_str_new((const char *)result, out_len);

	free(result);

	return retval;
}

VALUE rb_decrypt(VALUE mod, VALUE data, VALUE key) {
	unsigned char *result;
	VALUE retval;
	size_t data_len, out_len;

	Check_Type(data, T_STRING);
	Check_Type(key, T_STRING);

	data_len = RSTRING_LEN(data);

	result = xxtea_decrypt(RSTRING_PTR(data), data_len, RSTRING_PTR(key), &out_len);

	retval = rb_str_new((const char *)result, out_len);

	free(result);

	return retval;
}

#if (RUBY_VERSION_MAJOR == 1) && (RUBY_VERSION_MINOR > 8) || (RUBY_VERSION_MAJOR > 1)
VALUE rb_decrypt_utf8(VALUE mod, VALUE data, VALUE key) {
	return rb_enc_associate(rb_decrypt(mod, data, key), rb_utf8_encoding());
}
#endif

void Init_xxtea() {
    VALUE XXTEA = rb_define_module("XXTEA");
    rb_define_singleton_method(XXTEA, "encrypt", rb_encrypt, 2);
    rb_define_singleton_method(XXTEA, "decrypt", rb_decrypt, 2);
#if (RUBY_VERSION_MAJOR == 1) && (RUBY_VERSION_MINOR > 8) || (RUBY_VERSION_MAJOR > 1)
	rb_define_singleton_method(XXTEA, "decrypt_utf8", rb_decrypt_utf8, 2);
#endif
}<commit_msg>Fixed compile error on ruby 1.9+<commit_after>/**********************************************************\
|                                                          |
| xxtea.c                                                  |
|                                                          |
| XXTEA encryption algorithm library for Lua.              |
|                                                          |
| Encryption Algorithm Authors:                            |
|      <NAME>                                    |
|      <NAME>                                    |
|                                                          |
| Code Authors: <NAME> <<EMAIL>>                |
|               <NAME> <<EMAIL>>           |
| LastModified: Feb 8, 2016                                |
|                                                          |
\**********************************************************/

#include <ruby.h>
#ifdef RSTRING_NOEMBED
#include <ruby/encoding.h>
#endif
#include "xxtea.h"

VALUE rb_encrypt(VALUE mod, VALUE data, VALUE key) {
	unsigned char * result;
	VALUE retval;
	size_t data_len, out_len;

	Check_Type(data, T_STRING);
	Check_Type(key, T_STRING);

	data_len = RSTRING_LEN(data);

	result = xxtea_encrypt(RSTRING_PTR(data), data_len, RSTRING_PTR(key), &out_len);

	retval = rb_str_new((const char *)result, out_len);

	free(result);

	return retval;
}

VALUE rb_decrypt(VALUE mod, VALUE data, VALUE key) {
	unsigned char *result;
	VALUE retval;
	size_t data_len, out_len;

	Check_Type(data, T_STRING);
	Check_Type(key, T_STRING);

	data_len = RSTRING_LEN(data);

	result = xxtea_decrypt(RSTRING_PTR(data), data_len, RSTRING_PTR(key), &out_len);

	retval = rb_str_new((const char *)result, out_len);

	free(result);

	return retval;
}

#ifdef RSTRING_NOEMBED
VALUE rb_decrypt_utf8(VALUE mod, VALUE data, VALUE key) {
	return rb_enc_associate(rb_decrypt(mod, data, key), rb_utf8_encoding());
}
#endif

void Init_xxtea() {
    VALUE XXTEA = rb_define_module("XXTEA");
    rb_define_singleton_method(XXTEA, "encrypt", rb_encrypt, 2);
    rb_define_singleton_method(XXTEA, "decrypt", rb_decrypt, 2);
#ifdef RSTRING_NOEMBED
	rb_define_singleton_method(XXTEA, "decrypt_utf8", rb_decrypt_utf8, 2);
#endif
}
{'fraction_non_alphanumeric': 0.1532501076194576, 'fraction_numerical': 0.0075333620318553595, 'mean_word_length': 1.976937860345932, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7112300', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1405, 'n_words': 290}