Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fcasal/cryptoutils.jl

Cryptography and number-theory primitives in Julia
https://github.com/fcasal/cryptoutils.jl

continued-fractions cryptography julia number-theory prime-numbers

Last synced: about 1 month ago
JSON representation

Cryptography and number-theory primitives in Julia

Awesome Lists containing this project

README

        

# CryptoUtils

[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://fcasal.github.io/CryptoUtils.jl/dev/)

## Features

This package supports a number of cryptographic and number theory related primitives:
* generation of random prime numbers and safe primes;
* Jacobi and Legendre symbols;
* modular square roots;
* continued fractions of rationals and convergents;
* "bytes to number" and "number to bytes" conversion functions;
* RSA attacks:
* Wiener's attack with Dujella's extension;
* Factor `n = p*q`, given `e` and `d`.

## Installation
To install the package, simply run from the julia REPL:
```
julia> ]add CryptoUtils
```

## Documentation
Access the full [documentation](https://fcasal.github.io/CryptoUtils.jl/dev/).

## Example

```julia
julia> using CryptoUtils

julia> p = random_prime(512); q = random_prime(512); n = p*q # generate semiprime n
131745220523048272797760331579564741491214753542423769574982847786514776153155250573474208964071358407384440164414712528658264269591534035958596966591477455650082238340858337257106511821924740760868219278777077341070367621453029038918351903399126114774879588852878367966142856170535138849910785240708139225987

julia> e = 65537
65537

julia> d = invmod(e, (p-1)*(q-1)) # compute RSA decryption exponent
32362883641310315451899592262377172791965856192371946631485250568611645044625881242387678564972226360689108476233462883544705990145324113781489121643593621753163078450834460663942035227770596133499206721223993086064885467845603112395435294663436699341967664046213003429586468421266641276398515468366056248785

julia> factor_with_ed(n, e, d) # factor n with e and d
(11209007052907094316298587866392085453240213973638699831846376613053337678939099626874977325024647359864974367465362518878257931790980202563932031187056729, 11753513928682888932534842071560505691719602160983337271901213762089936749492510218729499032535262339600976674663969869808030961514878135483359095845990203)

julia> p
11209007052907094316298587866392085453240213973638699831846376613053337678939099626874977325024647359864974367465362518878257931790980202563932031187056729

julia> q
11753513928682888932534842071560505691719602160983337271901213762089936749492510218729499032535262339600976674663969869808030961514878135483359095845990203
```