# Gen_Prime 1.1.1

A way to transform a hash to a prime number

# Explanation

This is a method that allows calculate a prime number using a hash. The idea is really simple: we generate a number n passing the hash from 16-basis to a special basis, taken the value of tha char in 10-basis and multiply by 2i, where i is the position of the char in the string. This number n, we calculate the rest module 31, obtaining an other number d. We find the numbers x=2d-1 and y=2^(d+1)-1. We call a function that returns the first prime nuber in [x,y]. This will be our choice.

We apply module 31 for 2 reasons:

1. Every prime generate will be lower than 2^32.
2. We can work with up 2512. If every prime is lower than 232, we can use 16 or more hashes.

# Exemples

extern crate primes;

# fn main() {
let z:u128;
println!("Introduce a hash");
let mut a = String::new();
let v : Vec<&str>=a.split("").collect();
z=primes::hash_to_prime(v);
println!("{}", z);

# }

## #Outputs:

Introduce a hash a123dfe4758bc27237a

2147483647

Introduce a hash 074a4a47c445cf604b2ca687fed09fd8f3a78a16d20786b1a97aa6642fe0f87a8577a52cbace36bab6a6c40c3f1843be

1073741827

Introduce a hash 00eccf559792ee42e3ea26e394e9ab52ce569e47504d44715102cc0c2ab4f542dc54c383e8e13d360ebc57c5ede5e64b

16777259

Introduce a hash daa41c63b728ba70e6c377d7d17d9e53185fc720e7e6326626608eb1edc3735f67d963c303d92c9196583f3cd8739943

16553

## EXAMPLE 2

use std::io;
use std::u128;
extern crate bigint;
extern crate primes;
extern crate rand;
use bigint::U512;

# fn main() {
let mut mult:bigint::U512;
mult=U512::one();
loop{
println!("Introduce a hash");
let mut a = String::new();
let v : Vec<&str>=a.split("").collect();
let n2=v.len() as u32;
let res:u128;
let mut v2=Vec::with_capacity((n2-3) as usize);
for i in 0..n2-3 {
i as usize;
v2.push(v[(i+1) as usize]);
}
res=primes::hash_to_prime(v2);
mult=mult*(bigint::U512::from(res as usize));
println!("Do you want to enter another hash?[Y/N]");
let mut b = String::new();