Sha256: 57faa41f4b36fd98d24235f28abeb265958e813d57bcf75b3228330acf2e7aa3

Contents?: true

Size: 329 Bytes

Versions: 103

Compression:

Stored size: 329 Bytes

Contents

extern crate rand;

use rand::distributions::{IndependentSample, Range};

pub fn private_key(p: u64) -> u64 {
    Range::new(2, p).ind_sample(&mut rand::thread_rng())
}

pub fn public_key(p: u64, g: u64, a: u64) -> u64 {
    g.pow(a as u32) % p
}

pub fn secret(p: u64, b_pub: u64, a: u64) -> u64 {
    b_pub.pow(a as u32) % p
}

Version data entries

103 entries across 103 versions & 1 rubygems

Version Path
trackler-2.2.1.176 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.175 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.174 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.173 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.172 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.171 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.170 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.169 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.167 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.166 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.165 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.164 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.163 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.162 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.161 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.160 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.159 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.158 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.157 tracks/rust/exercises/diffie-hellman/example.rs
trackler-2.2.1.156 tracks/rust/exercises/diffie-hellman/example.rs