[Archipelago-submits] [145] trunk/oneliner/ext/superstring_ext.c: in the middle of making decoding block_size sensitive
nobody at rubyforge.org
nobody at rubyforge.org
Wed Dec 27 07:45:43 EST 2006
Revision: 145
Author: zond
Date: 2006-12-27 07:45:42 -0500 (Wed, 27 Dec 2006)
Log Message:
-----------
in the middle of making decoding block_size sensitive
Modified Paths:
--------------
trunk/oneliner/ext/superstring_ext.c
Modified: trunk/oneliner/ext/superstring_ext.c
===================================================================
--- trunk/oneliner/ext/superstring_ext.c 2006-12-27 12:31:45 UTC (rev 144)
+++ trunk/oneliner/ext/superstring_ext.c 2006-12-27 12:45:42 UTC (rev 145)
@@ -153,6 +153,20 @@
}
}
+static void
+set_value2(VALUE aux_blocks, int index, char *value, VALUE self, VALUE decode_status, int block_size)
+{
+ if ((index * block_size) < RSTRING(self)->len) {
+ rb_str_modify(self);
+ memcpy(RSTRING(self)->ptr + (index * block_size), value, block_size);
+ set_is_known(decode_status, index);
+ } else {
+ rb_str_modify(aux_blocks);
+ memcpy(RSTRING(aux_blocks)->ptr + ((index - (RSTRING(self)->len / block_size)) * block_size), value, block_size);
+ set_is_known(decode_status, index);
+ }
+}
+
//
// Get the value at index from data or aux blocks.
//
@@ -166,6 +180,16 @@
}
}
+static char*
+get_value2(VALUE aux_blocks, int index, VALUE self, int block_size)
+{
+ if ((index * block_size) < RSTRING(self)->len) {
+ return RSTRING(self)->ptr + (index * block_size);
+ } else {
+ return RSTRING(aux_blocks)->ptr + ((index - (RSTRING(self)->len / block_size) ) * block_size);
+ }
+}
+
//
// Get a random check block of block_size from our data and aux blocks and append it to chunk at index.
//
@@ -275,13 +299,13 @@
VALUE aux_blocks = (_aux_blocks);
int seed = ( (int *) RSTRING(chunk)->ptr )[0];
int size = ( (int *) RSTRING(chunk)->ptr )[1];
- int tmp, tmp2;
+ int tmp;
char got_new_block = 0;
VALUE rnd_ctx = get_aes_context();
int block_size = NUM2INT(block_size_value);
SEED(RSTRING(rnd_ctx)->ptr, seed);
- for (tmp = 8; tmp < RSTRING(chunk)->len; tmp++) {
+ for (tmp = 8; tmp < RSTRING(chunk)->len; tmp = tmp + block_size) {
int degree;
//printf("looking at check block %d:", tmp);
@@ -289,10 +313,10 @@
degree = get_degree(size, rnd_ctx);
if (degree == 1) {
int block_nr;
- block_nr = RANDOM(RSTRING(rnd_ctx)->ptr, size + RSTRING(aux_blocks)->len);
+ block_nr = RANDOM(RSTRING(rnd_ctx)->ptr, (size + RSTRING(aux_blocks)->len) / block_size);
//printf(" %d", block_nr);
if (!get_is_known(decode_status, block_nr)) {
- set_value(aux_blocks, block_nr, RSTRING(chunk)->ptr[tmp], self, decode_status);
+ set_value2(aux_blocks, block_nr, RSTRING(chunk)->ptr + tmp, self, decode_status, block_size);
got_new_block = 1;
//printf(" => [%d]=%d", block_nr, RSTRING(chunk)->ptr[tmp]);
} else {
@@ -301,15 +325,23 @@
} else {
int missing_blocks;
int missing_block = 0;
- char xor_sum = RSTRING(chunk)->ptr[tmp];
+ int tmp2;
+ char xor_sum[block_size];
+ memcpy(xor_sum, RSTRING(chunk)->ptr + tmp, block_size);
+
for (missing_blocks = tmp2 = degree; tmp2 > 0; tmp2--) {
int block_nr;
//printf(" %d", block_nr);
block_nr = RANDOM(RSTRING(rnd_ctx)->ptr, size + RSTRING(aux_blocks)->len);
if (get_is_known(decode_status, block_nr)) {
+ int tmp3;
+ char *this_value = get_value2(aux_blocks, block_nr, self, block_size);
+
missing_blocks--;
- xor_sum = xor_sum ^ get_value(aux_blocks, block_nr, self);
+ for (tmp3 = 0; tmp3 < block_size; tmp3++) {
+ xor_sum[tmp3] = xor_sum[tmp3] ^ this_value[tmp3];
+ }
//printf("!");
} else {
missing_block = block_nr;
@@ -317,7 +349,7 @@
}
}
if (missing_blocks == 1) {
- set_value(aux_blocks, missing_block, xor_sum, self, decode_status);
+ set_value2(aux_blocks, missing_block, xor_sum, self, decode_status, block_size);
got_new_block = 1;
//printf(" => [%d]=%d", missing_block, xor_sum);
}
More information about the Archipelago-submits
mailing list