Rizin
unix-like reverse engineering framework and cli tools
base91.c File Reference
#include <string.h>
#include <rz_util.h>

Go to the source code of this file.

Functions

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

Variables

static const char b91 []
 

Function Documentation

◆ get_char_index()

int get_char_index ( const char  c)

Definition at line 18 of file base91.c.

18  {
19  int i;
20  for (i = 0; i < 91; i++) {
21  if (b91[i] == c) {
22  return i;
23  }
24  }
25  return -1;
26 }
lzma_index ** i
Definition: index.h:629
static const char b91[]
Definition: base91.c:8
#define c(i)
Definition: sha256.c:43

References b91, c, and i.

Referenced by rz_base91_decode().

◆ 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
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 }

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

Referenced by update().

Variable Documentation

◆ b91

const char b91[]
static
Initial value:
= { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '!', '#', '$', '%', '&', '(', ')', '*',
'+', ',', '.', '/', ':', ';', '<', '=', '>', '?',
'@', '[', ']', '^', '_', '`', '{', '|', '}', '~', '"' }

Definition at line 8 of file base91.c.

Referenced by get_char_index(), and rz_base91_encode().