1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#![cfg(feature="inclramp")]
extern crate framp as ramp;
use rand::{OsRng};
use super::traits::*;
impl Samplable for ramp::Int {
fn sample_below(upper: &Self) -> Self {
use self::ramp::RandomInt;
let mut rng = OsRng::new().unwrap();
rng.gen_uint_below(upper)
}
fn sample(bitsize: usize) -> Self {
use self::ramp::RandomInt;
let mut rng = OsRng::new().unwrap();
rng.gen_uint(bitsize)
}
fn sample_range(lower: &Self, upper: &Self) -> Self {
use self::ramp::RandomInt;
let mut rng = OsRng::new().unwrap();
rng.gen_int_range(lower, upper)
}
}
impl NumberTests for ramp::Int {
fn is_zero(me: &Self) -> bool { me == &0 }
fn is_even(me: &Self) -> bool { me.is_even() }
fn is_negative(me: &Self) -> bool { me < &0 }
}
impl ModularArithmetic for ramp::Int {
fn divmod(dividend: &Self, module: &Self) -> (Self, Self) {
dividend.divmod(module)
}
fn modpow(base: &Self, exponent: &Self, modulus: &Self) -> Self {
base.modpow(exponent, modulus)
}
}
impl ConvertFrom<ramp::Int> for usize {
fn _from(x: &ramp::Int) -> usize {
usize::from(x)
}
}
impl ConvertFrom<ramp::Int> for u8 {
fn _from(x: &ramp::Int) -> u8 {
u8::from(x)
}
}
impl ConvertFrom<ramp::Int> for u16 {
fn _from(x: &ramp::Int) -> u16 {
u16::from(x)
}
}
impl ConvertFrom<ramp::Int> for u32 {
fn _from(x: &ramp::Int) -> u32 {
u32::from(x)
}
}
impl ConvertFrom<ramp::Int> for u64 {
fn _from(x: &ramp::Int) -> u64 {
u64::from(x)
}
}
impl BitManipulation for ramp::Int {
fn set_bit(self: &mut Self, bit: usize, bit_val: bool) {
self.set_bit(bit as u32, bit_val);
}
}
pub type BigInteger = ramp::Int;