Rizin
unix-like reverse engineering framework and cli tools
rz_base91.h File Reference
#include <rz_types.h>

Go to the source code of this file.

Functions

RZ_API int rz_base91_encode (char *bout, const ut8 *bin, int len)
 
RZ_API int rz_base91_decode (ut8 *bout, const char *bin, int len)
 

Function Documentation

◆ rz_base91_decode()

RZ_API int rz_base91_decode ( ut8 bout,
const char *  bin,
int  len 
)

Definition at line 28 of file base91.c.

28  {
29  int in, out;
30  int v = -1;
31  int b = 0;
32  int n = 0;
33  int c;
34  if (len < 0) {
35  len = strlen(bin);
36  }
37  for (in = out = 0; in < len; in++) {
38  c = get_char_index(bin[in]);
39  if (c == -1) {
40  continue;
41  }
42  if (v < 0) {
43  v = c;
44  } else {
45  v += c * 91;
46  b |= (v << n);
47  if ((v & 8191) > 88) {
48  n += 13;
49  } else {
50  n += 14;
51  }
52  while (true) {
53  bout[out++] = b & 255;
54  b >>= 8;
55  n -= 8;
56  if (n <= 7) {
57  break;
58  }
59  }
60  v = -1;
61  }
62  }
63  if (v + 1) {
64  bout[out++] = (b | v << n) & 255;
65  }
66  return out;
67 }
size_t len
Definition: 6502dis.c:15
int get_char_index(const char c)
Definition: base91.c:18
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
const char * v
Definition: dsignal.c:12
int n
Definition: mipsasm.c:19
#define b(i)
Definition: sha256.c:42
#define c(i)
Definition: sha256.c:43
Definition: malloc.c:26

References b, c, get_char_index(), in, len, n, out, and v.

Referenced by update().

◆ rz_base91_encode()

RZ_API int rz_base91_encode ( char *  bout,
const ut8 bin,
int  len 
)

Definition at line 69 of file base91.c.

69  {
70  int in, out;
71  int v = 0;
72  int b = 0;
73  int n = 0;
74  if (len < 0) {
75  len = strlen((const char *)bin);
76  }
77  for (in = out = 0; in < len; in++) {
78  b |= (bin[in] << n);
79  n += 8;
80  if (n > 13) {
81  v = b & 8191;
82  if (v > 88) {
83  b >>= 13;
84  n -= 13;
85  } else {
86  v = b & 16383;
87  b >>= 14;
88  n -= 14;
89  }
90  bout[out++] = b91[v % 91];
91  bout[out++] = b91[v / 91];
92  }
93  }
94  if (n) {
95  bout[out++] = b91[b % 91];
96  if (n > 7 || b > 90) {
97  bout[out++] = b91[b / 91];
98  }
99  }
100  return out;
101 }
static const char b91[]
Definition: base91.c:8

References b, b91, in, len, n, out, and v.

Referenced by update().