comparison base85.c @ 0:cd351af3a8d2 migout

import source
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Thu, 27 Mar 2008 20:03:52 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:cd351af3a8d2
1 #include "types.h"
2 #include "base85.h"
3
4 int base85_encode(u8 *in, u8 *out, int inlen)
5 {
6 u32 t;
7 u8 *src = in;
8 u8 *dst = out;
9
10 while (in + inlen > src) {
11 t = ((u32) src[0] << 24) |
12 ((u32) src[1] << 16) |
13 ((u32) src[2] << 8) |
14 ((u32) src[3]);
15 src += 4;
16
17 /* compression of all zero group */
18 if (!t) {
19 *dst = 'z';
20 dst++;
21 continue;
22 }
23
24 dst[4] = (t % 85) + 33; t /= 85;
25 dst[3] = (t % 85) + 33; t /= 85;
26 dst[2] = (t % 85) + 33; t /= 85;
27 dst[1] = (t % 85) + 33; t /= 85;
28 dst[0] = t + 33;
29 dst += 5;
30 }
31
32 return (int) (dst - out);
33 }