Skip to content

Commit 449170f

Browse files
added readme and license
1 parent 11e78e7 commit 449170f

File tree

5 files changed

+72
-9
lines changed

5 files changed

+72
-9
lines changed

LICENSE

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Apache License
2+
Version 2.0, January 2004
3+
http://www.apache.org/licenses/
4+
5+
Copyright 2024 Aztec Labs
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# noir_base64
2+
3+
A library to encode ASCII into Base64 and decode Base64 into ASCII
4+
5+
# Usage
6+
7+
### `fn base64_encode`
8+
Takees an input byte array of ASCII characters and produces an output byte array of base64-encoded characters. The 6-bit base64 characters are packed into a concatenated byte array (e.g. 4 bytes of ASCII produce 3 bytes of encoded Base64)
9+
10+
### `fn base64_decode`
11+
Takes an input byte array of packed base64 characters and produces an output byte array of ASCII characters (e.g. 3 input bytes of base64 produces 4 output bytes of ASCII)
12+
13+
### `fn base64_encode_elements`
14+
Takes an input byte array of ASCII characters and produces an output byte array of base64-encoded characters. Data is not packed i.e. each output array element maps to a 6-bit base64 character
15+
16+
### `fn base64_decode_elements`
17+
Takes an input byte array of base64 characters and produces an output byte array of ASCII characters. Input data is not packed i.e. each input element maps to a 6-bit base64 character
18+
19+
### Example usage
20+
(see tests in `lib.nr` for more examples)
21+
22+
```
23+
use dep::noir_base64;
24+
fn encode() {
25+
// Raw bh: GxMlgwLiypnVrE2C0Sf4yzhcWTkAhSZ5+WERhKhXtlU=
26+
// Translated directly to ASCII
27+
let input: [u8; 44] = [
28+
71, 120, 77, 108, 103,
29+
119, 76, 105, 121, 112,
30+
110, 86, 114, 69, 50,
31+
67, 48, 83, 102, 52,
32+
121, 122, 104, 99, 87,
33+
84, 107, 65, 104, 83,
34+
90, 53, 43, 87, 69,
35+
82, 104, 75, 104, 88,
36+
116, 108, 85, 61
37+
];
38+
39+
// will produce packed byte array of base64 chars:
40+
/*
41+
[
42+
27, 19, 37, 131, 2, 226, 202, 153, 213, 172,
43+
77, 130, 209, 39, 248, 203, 56, 92, 89, 57,
44+
0, 133, 38, 121, 249, 97, 17, 132, 168, 87,
45+
182, 85
46+
]
47+
*/
48+
let result: [u8; 32] = noir_base64::base64_encode(input);
49+
}
50+
```
51+
52+
# Costs
53+
54+
`base64_encode_elements` will encode an array of 44 ASCII bytes in ~470 gates, plus a ~256 gate cost to initialize an encoding lookup table (the initialization cost is incurred once regardless of the number of decodings)
55+

info.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/lib.nr

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,6 @@ pub fn base64_decode<let InputBytes: u64, let OutputElements: u64>(input: [u8; I
175175
base64_decode_elements(result)
176176
}
177177

178-
// // to measure, run `info.sh`
179-
// fn main(x: [u8; 44]) {
180-
// for i in 0..1 {
181-
// let r: [u8; 32] = base64_encode(x);
182-
// println(f"{r}");
183-
// }
184-
// }
185178

186179
// ooook so we take ascii and encode as base64, we get an undefined character
187180
#[test]

0 commit comments

Comments
 (0)