https://github.com/danielost/big-numbers
BigNumber implementation in Golang
https://github.com/danielost/big-numbers
bignumber cryptography
Last synced: 11 days ago
JSON representation
BigNumber implementation in Golang
- Host: GitHub
- URL: https://github.com/danielost/big-numbers
- Owner: danielost
- Created: 2023-10-13T17:14:14.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-17T18:48:05.000Z (over 1 year ago)
- Last Synced: 2025-02-16T19:48:51.481Z (3 months ago)
- Topics: bignumber, cryptography
- Language: Go
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Big Numbers
Cryptography for developers by Distributed Lab - Practice #2## Work done
* `src/bignumbers.go` - the implementation of a Big Number.* `src/uint.go` - the data type used by `BigNumber`. Just a convenience that lets you convert a `uint64` to different notations and perform basic binary and arithmetic operations.
* `arithmeticops.go/binaryops.go` - interfaces that the `BigNumber` needs to implement.
* `src/util` - utility functions.
* `src/validators` - set of functions to validate values.
* `tests/` - contains the tests.
## List of operations
| **#** | **Operation** | **Name** |
|--- |--- |--- |
| 1 | INV | bitwise inversion |
| 2 | XOR | bitwise exclusive or |
| 3 | OR | bitwise or |
| 4 | AND | bitwise and |
| 5 | shiftR | shift to the right by n bits |
| 6 | shiftL | shift to the left by n bits |
| 7 | ADD | addition |
| 8 | SUB | subtraction |
| 9 | MOD | modulo |## Testing
To run the tests, execute one of the following commands in the root folder:
```bash
go test .\tests\
```
```bash
go test -v .\tests\
```When pushing, all the tests run automatically with the GitHub Actions.
## Example
```go
import (
"fmt"bignumbers "github.com/danielost/big-numbers/src"
)func foo() {
var bnA bignumbers.BigNumber
var bnB bignumbers.BigNumberbnA.SetHex("51bf608414ad5726a3c1bec098f77b1b54ffb2787f8d528a74c1d7fde6470ea4")
bnB.SetHex("403db8ad88a3932a0b7e8189aed9eeffb8121dfac05c3512fdb396dd73f6331c")bnC := bnA.XOR(bnB)
fmt.Println(bnC.GetHex())
}
```