From b997dc65fd770399018bb1ed6fe28a0101b5d4e0 Mon Sep 17 00:00:00 2001 From: malte Date: Sun, 18 May 2014 18:28:39 +0200 Subject: [PATCH] POLY->ASCII: added inline comments. --- src/ascii_poly.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ascii_poly.c b/src/ascii_poly.c index aefaac5..105311a 100644 --- a/src/ascii_poly.c +++ b/src/ascii_poly.c @@ -19,11 +19,11 @@ * MA 02110-1301 USA */ -#include "ascii_poly.h" #include "context.h" #include "err.h" #include "mem.h" #include "poly.h" +#include "ascii_poly.h" #include #include @@ -101,16 +101,24 @@ char *polynom_to_ascii(pb_poly *to_ascii) char *tmp_ptr = string; u_int8_t ascii_value = 0; + /* every char */ for (u_int32_t i = 0; i < length_poly; i += ASCII_DIGITS) { + /* every bit*/ for (u_int32_t j = 0; j < ASCII_DIGITS; j++) { + /* get the bit */ if (mp_toradix(&(to_ascii->terms[i + j]), &bit_buffer, 2)) { return NULL; } + /* bit as integer */ u_int8_t bit = atoi(&bit_buffer); + /* bitshift to the left */ ascii_value <<= 1; + /* set the new bit and keep the other */ ascii_value |= bit; } - *tmp_ptr++ = ascii_value; + /* char into string */ + *tmp_ptr++ = (char) ascii_value; + /* reset for next char */ ascii_value = 0; } return string;