Exemple #1
0
static char *
decode_cchar(char *source, cchar_t *fillin, cchar_t *target)
{
    int color;
    attr_t attr = fillin->attr;
    wchar_t chars[CCHARW_MAX];
    int append = 0;
    int value = 0;

    T(("decode_cchar  '%s'", source));
    *target = blank;
#if NCURSES_EXT_COLORS
    color = fillin->ext_color;
#else
    color = (int) PAIR_NUMBER(attr);
#endif
    source = decode_attr(source, &attr, &color);
    memset(chars, 0, sizeof(chars));
    source = decode_char(source, &value);
    chars[0] = (wchar_t) value;
    /* handle combining characters */
    while (source[0] == MARKER && source[1] == APPEND) {
	source += 2;
	source = decode_char(source, &value);
	if (++append < CCHARW_MAX) {
	    chars[append] = (wchar_t) value;
	}
    }
    setcchar(target, chars, attr, (short) color, NULL);
    return source;
}
Exemple #2
0
/*
 * Decode a base_n-encoded string into a byte sequence.
 */
bool raw_decode_base_n(BIGNUM *bn, const char *src, size_t len, int base)
{
	const char *enc;

	BN_zero(bn);

	assert(base == 16 || base == 58);
	switch (base) {
	case 16:
		enc = enc_16;
		break;
	case 58:
		enc = enc_58;
		break;
	}

	while (len) {
		char current = *src;

		if (base == 16)
			current = tolower(current);	/* TODO: Not in ccan. */
		int val = decode_char(current, enc);
		if (val < 0) {
			BN_free(bn);
			return false;
		}
		BN_mul_word(bn, base);
		BN_add_word(bn, val);
		src++;
		len--;
	}

	return true;
}
Exemple #3
0
static char *decode_parameter(const char **query, int is_name)
{
	const char *q = *query;
	struct strbuf out;

	strbuf_init(&out, 16);
	do {
		unsigned char c = *q;

		if (!c)
			break;
		if (c == '&' || (is_name && c == '=')) {
			q++;
			break;
		}

		if (c == '%') {
			int val = decode_char(q + 1);
			if (0 <= val) {
				strbuf_addch(&out, val);
				q += 3;
				continue;
			}
		}

		if (c == '+')
			strbuf_addch(&out, ' ');
		else
			strbuf_addch(&out, c);
		q++;
	} while (1);
	*query = q;
	return strbuf_detach(&out, NULL);
}
Exemple #4
0
static char* decodeA(const char* str)
{
    static char decoded[1024];
    char*       ptr;
    size_t      len,i;

    len = strlen(str) / 2;
    if (!len--) return NULL;
    if (len >= sizeof(decoded))
    {
        fprintf(stderr, "string is too long!\n");
        assert(0);
    }
    ptr = decoded;
    for (i = 0; i < len; i++)
        ptr[i] = (decode_char(str[2 * i]) << 4) | decode_char(str[2 * i + 1]);
    ptr[len] = '\0';
    return ptr;
}
Exemple #5
0
static void decode_str(char *str)
{
	while(*str)
	{
		if(*str >= 65 && *str <= 90)
		{
			*str = decode_char(*str);
		}
		str++;
	}
}
Exemple #6
0
    bool decode(const char* encoded, size_t encoded_len, BigInt* output)
    {
        if (encoded == 0 || encoded_len == 0) 
            return 0;
        
        if (encoded_len == -1)
            encoded_len = strlen(encoded);

        if (encoded_len >= kMaxBase58Length) 
            return 0;

        if (output == 0)
            return 0;

        BigInt output_num = 0;

        size_t unprocessed = encoded_len;
        while (--unprocessed) {

            int idx = encoded_len - unprocessed - 1;
            int num = decode_char(encoded[idx]);
            if (num == -1) {
                return 0;
            }

            output_num += num;
            output_num *= 58;
        }

        int remainder = decode_char(encoded[encoded_len-1]);
        if (remainder == -1) {
            return 0;
        }

        *output = output_num + remainder;

        return true;
    }
Exemple #7
0
static char *
decode_chtype(char *source, chtype fillin, chtype *target)
{
    attr_t attr = ChAttrOf(fillin);
    int color = PAIR_NUMBER((int) attr);
    int value;

    T(("decode_chtype '%s'", source));
    source = decode_attr(source, &attr, &color);
    source = decode_char(source, &value);
    *target = (ChCharOf(value) | attr | (chtype) COLOR_PAIR(color));
    /* FIXME - ignore combining characters */
    return source;
}
void vigenere(char* dst, char* src, char* pass, int encode) {
    int i;
    int j;
    int pass_len = strlen(pass);

    for (i = 0, j = 0; i < strlen(src); i++, j++) {
        if (encode)
            dst[i] = encode_char(src[i], pass[j % pass_len]);
        else
            dst[i] = decode_char(src[i], pass[j % pass_len]);
    }

    /* Ensure trailing null character since `dst` may not have been initialized
     * yet.
     */
    dst[i] = '\0';
}
Exemple #9
0
// translate_read() ist die inverse Operation zu translate_write, wir moechten Informationen von einem Device lesen, muessen die jedoch vorher dekodieren 
ssize_t translate_read(struct file *filp, char __user *buf,
		       size_t count,loff_t *f_pos) {
    struct translate_dev *dev = filp->private_data;
    int num_copied_items = 0;
    int p_reader = (dev->read_pos - dev->buffer) / sizeof(char);

#ifdef DEBUG_MESSAGES
    printk(KERN_NOTICE "translate_read()\n");
#endif

    while (num_copied_items < count) {
        if (dev->items == 0) {

#ifdef DEBUG_MESSAGES
    printk(KERN_NOTICE "translate_read: buffer empty, read %d chars \n",num_copied_items);
#endif

	    return num_copied_items;
	}
	
        // Zu diesem Zeitpunk haben wir die Informationen
	// und der User moechte diese lesen, wir dekodieren den Buffer
	// und uebergeben dann die Informationen dem User
	// Falls das Device translate1 ist, dann dekodiere
        if (MINOR(dev->cdev.dev) == (MINOR_START_IDX + 1)) {
            decode_char(dev->read_pos);
        }
        
        if (copy_to_user(buf, dev->read_pos, 1)) {
            return -EFAULT;
        }

        // Pointer aktualisieren
        dev->read_pos = dev->buffer + ((p_reader + 1) % translate_bufsize)* sizeof(char);
        p_reader = (dev->read_pos - dev->buffer) / sizeof(char);
        buf += sizeof(char);
	
	// Counter aktualisieren
        num_copied_items++;
        dev->items--;
    }
    
    return num_copied_items;
}
Exemple #10
0
static size_t decode_sequence(const char *coded, char *plain) {
   assert(coded && plain);

   plain[0] = '\0';
   for (int block = 0; block < 8; block++) {
      int offset = get_offset(block);
      int octet = get_octet(block);

      int c = decode_char(coded[block]);
      if (c < 0) {
         return (size_t)octet;
      }

      plain[octet] |= shift_left(c, offset);
      if (offset < 0) {
         assert(octet < 4);
         plain[octet + 1] = shift_left(c, 8 + offset);
      }
   }
   return 5;
}
void decode_buffer(unsigned char *buffer){

	printf("Start decoding the packet!!\n");
	
	unsigned int ans = decode_int(buffer);
	buffer +=4;
	//unsigned int langth = decode_int(buffer);
	unsigned char *str = malloc(sizeof(char) * NAMELENGTH);
	str = decode_char(buffer); 
	
	printf("decoded buffer is: %s, %d\n",  str, ans);

	while(send_ack(1, -1) < 0){

		printf("failed ack\n");

	}
	connection = 1;
	
	return;

}
Exemple #12
0
// implementation of what happens when someone now wants to read
// into our device. we got much help form others groups here.
// this is very similar to the write process
ssize_t translate_read(struct file *filp, char __user *buf,
                                    size_t count,loff_t *f_pos) {
    struct translate_dev *dev = filp->private_data;
    int num_copied_items = 0;
    int p_reader = (dev->read_pos - dev->buffer) / sizeof(char);
    
    DEBUG(printk(KERN_NOTICE "translate_read()\n"));
    
    while (num_copied_items < count) {
        if (dev->items == 0) {
            DEBUG(printk(KERN_NOTICE "translate_read: buffer empty, read %d chars \n",num_copied_items));
            return num_copied_items;
        }
        
        // because we're got the information now and the user want to read them
        // we'll decode our buffer (if translate1) and THEN hand it over to the user.
        
        // if the device is translate1, then decode
        if (MINOR(dev->cdev.dev) == (MINOR_BEGINNING + 1)) {
            decode_char(dev->read_pos);
        }
        
        if (copy_to_user(buf, dev->read_pos, 1)) {
            return -EFAULT;
        }
        
        // update pointers
        dev->read_pos = dev->buffer + ((p_reader + 1) % translate_bufsize)* sizeof(char);
        p_reader = (dev->read_pos - dev->buffer) / sizeof(char);
        buf += sizeof(char);
        
        // update counters
        num_copied_items++;
        dev->items--;
    }
    
    return num_copied_items;
}