Skip to content

Commit

Permalink
Add assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-kanodia committed Aug 15, 2023
0 parents commit 7da2502
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: test

on:
push:
branches: [main, master]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Nargo
uses: noir-lang/[email protected]
with:
toolchain: nightly

- name: Run tests
run: |
nargo test
7 changes: 7 additions & 0 deletions Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "noir_toy_hashing"
type = "bin"
authors = [""]
compiler_version = "0.9.1"

[dependencies]
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## Noir FNV Hashing

The goal of this assignment is to learn the basics of Noir by implementing FNV hashing.

FNV (Fowler-Noll-Vo) hashing is a family of non-cryptographic hash functions that are designed to be fast and efficient while producing a relatively good distribution of hash values.

The FNV hash algorithm operates on a byte sequence and produces a hash value. It starts with an initial value, usually a prime number, and then processes each byte of the input data, updating the hash value using a simple multiplication and XOR operation.

The basic implementation of an FNV algorithm in python is given below:

```python
def fnv_hash(data):
size = 2**32
hash_value = 0x811C9DC5
prime = 0x1000193

for byte in data:
product = (hash_value * prime) % size
hash_value = (product ^ byte)

return hash_value
```

The function when given a value of `0x079A6F9C` returns the hashed value `0x71233de7`. Your goal for this assignment is to implement this in Noir. Use the same values of size, initial value and prime number.

## Evaluation

- Create a fork of this repo

- Clone the forked repo. You can use the following command after replacing the `CLONE_URL` with the clone url of your repo

```
git clone CLONE_URL
```

- Make changes to the `src/main.nr` file. Add your hashing logic to `calculate_hash` function. The function should take in a value and return its hash.

- Run Tests
```
nargo test
```

- Push your changes to `main` branch of your forked repo.

- Submit your name, email and link to your forked repo [here](https://airtable.com/apppwJwKgRGomJLLY/shrlDlkFR3XZKZRmN).

## Reference

- [Noir Docs](https://noir-lang.org/)
20 changes: 20 additions & 0 deletions src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
global PRIME: u32 = 16777619;

fn main(value: u32, hash_value: pub u32){
let calculated_hash_value = calculate_hash(value);

assert(calculated_hash_value == hash_value);
}

fn calculate_hash(num: u32) -> u32 {

}

#[test]
fn test_main() {
let num = 127561628;
let hash = calculate_hash(num);

assert(hash == 0x71233de7);
main(num, hash);
}

0 comments on commit 7da2502

Please sign in to comment.