forked from ryancdotorg/brainflayer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hex.h
30 lines (26 loc) · 1.11 KB
/
hex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* 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: */