diff options
author | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2008-10-08 17:26:26 +0200 |
---|---|---|
committer | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2008-10-08 17:26:26 +0200 |
commit | 3fa2e6d50393d0acd683a23989a5b49e615adc66 (patch) | |
tree | 04b2fd59d636ed8458cd8c0eb9a1260e5d83c23c /libpiano | |
parent | 56fbdc2372f1afbe90bc0386ef714115884dbca3 (diff) | |
download | pianobar-windows-3fa2e6d50393d0acd683a23989a5b49e615adc66.tar.gz pianobar-windows-3fa2e6d50393d0acd683a23989a5b49e615adc66.tar.bz2 pianobar-windows-3fa2e6d50393d0acd683a23989a5b49e615adc66.zip |
piano: Faster hex-encode algo
Don't worry about it; you will not notice the speed improvement on
modern hardware ;)
Same as hex-decode, but inverted and more complex.
Diffstat (limited to 'libpiano')
-rw-r--r-- | libpiano/src/crypt.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/libpiano/src/crypt.c b/libpiano/src/crypt.c index 43edd0c..7e2bb80 100644 --- a/libpiano/src/crypt.c +++ b/libpiano/src/crypt.c @@ -149,7 +149,6 @@ void PianoBytesToInts (const char *strInput, unsigned int **retArrInts, /* we must not read beyond the end of the string, so be a bit * paranoid */ - shift = 24; i = 0; j = 0; while (i < strInputN) { @@ -212,10 +211,17 @@ void PianoEncipherInts (const unsigned int *plainInts, size_t plainIntsN, char *PianoIntsToHexString (const unsigned int *arrInts, size_t arrIntsN) { /* 4 bytes as hex (= 8 chars) */ char *hexStr = calloc (arrIntsN * 4 * 2 + 1, sizeof (*hexStr)); - size_t i; - - for (i = 0; i < arrIntsN; i++) { - snprintf (hexStr+i*4*2, arrIntsN * 4 * 2 + 1, "%08x", arrInts[i]); + size_t i, writePos; + unsigned char *intMap = (unsigned char *) arrInts; + size_t intMapN = arrIntsN * sizeof (*arrInts); + + for (i = 0; i < intMapN; i++) { + /* we need to swap the bytes again */ + writePos = i + (4 - (i % 4) * 2) - 1; + hexStr[writePos*2] = (intMap[i] & 0xf0) < 0xa0 ? (intMap[i] >> 4) + + '0' : (intMap[i] >> 4) + 'a' - 10; + hexStr[writePos*2+1] = (intMap[i] & 0x0f) < 0x0a ? (intMap[i] & 0x0f) + + '0' : (intMap[i] & 0x0f) + 'a' - 10; } return hexStr; } |