/* Copyright (c) 2015 Ryan Castellucci, All Rights Reserved */ #ifndef __BRAINFLAYER_HEX_H_ #define __BRAINFLAYER_HEX_H_ static const unsigned char unhex_tab[80] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static inline unsigned char * unhex(unsigned char *str, size_t str_sz, unsigned char *unhexed, size_t unhexed_sz) { int i, j; for (i = j = 0; i < str_sz && j < unhexed_sz; i += 2, ++j) { unhexed[j] = (unhex_tab[str[i+0]&0x4f] & 0xf0)| (unhex_tab[str[i+1]&0x4f] & 0x0f); } return unhexed; } unsigned char * hex(unsigned char *, size_t, unsigned char *, size_t); #endif /* __BRAINFLAYER_HEX_H_ */ /* vim: set ts=2 sw=2 et ai si: */