forked from ryancdotorg/brainflayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d653c1
commit bbec415
Showing
5 changed files
with
60 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* Copyright (c) 2015 Ryan Castellucci, All Rights Reserved */ | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdio.h> | ||
|
||
#include "hex.h" | ||
|
||
unsigned char * | ||
hex(unsigned char *buf, size_t buf_sz, | ||
unsigned char *hexed, size_t hexed_sz) { | ||
int i, j; | ||
--hexed_sz; | ||
for (i = j = 0; i < buf_sz && j < hexed_sz; ++i, j += 2) { | ||
sprintf(hexed+j, "%02x", buf[i]); | ||
} | ||
hexed[j] = 0; // null terminate | ||
return hexed; | ||
} | ||
|
||
/* vim: set ts=2 sw=2 et ai si: */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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: */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters