```  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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
```
```//! LAST ACTUALITZATION: INCREASE THE SPEED
//!
//! # Explaining
//!
//! 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 2^{i}, 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=2^{d}-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 2^{512}. If every prime is lower than 2^{32}, we can use 16 or more hashes.
//!
//! ```toml
//!
//! [dependencies]
//! Gen_Prime = "1.1.5"
//!
//! ```
//!
//! # Examples
//!
//! -------------------------------------------------------------------------------------------------------
//! EXAMPLE 1
//!
//! ```rust
//! 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
//!
//! ```rust
//! 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]);
//!         } //this lines are to safe each char in one component of a vector, and to delete white spaces
//!         res=primes::hash_to_prime(v2); //Generating a prime
//!         mult=mult*(bigint::U512::from(res as usize)); //Product of the primes
//!         println!("Do you want to enter another hash?[Y/N]");
//!         let mut b = String::new();
//!         let b : char = b.trim().parse().expect("Please, input one choice");
//!         if b=='N' || b=='n'{
//!             break;
//!         }
//!     }
//!     println!("{}", mult);
//!  # }
//!
//! ```
//!
//! ## Output
//!
//! Introduce a hash
//!
//! daa41c63b728ba70e6c377d7d17d9e53185fc720e7e6326626608eb1edc3735f67d963c303d92c9196583f3cd8739943
//!
//! 19
//!
//! r:100
//!
//! Do you want to enter another hash?[Y/N]
//!
//! Y
//!
//! Introduce a hash
//!
//! 0907b5ff1b7d6f7b2639ca00565c8f42cbf7529b992f825b2676ec30c294b477b913476d6a508da9d195f1dacc893173
//!
//! 23
//!
//! r:39
//!
//! Do you want to enter another hash?[Y/N]
//!
//! Y
//!
//! Introduce a hash
//!
//!
//! 27
//!
//! r:55
//!
//! Do you want to enter another hash?[Y/N]
//!
//! Y
//!
//! Introduce a hash
//!
//!
//! 8
//!
//! r:49
//!
//! Do you want to enter another hash?[Y/N]
//!
//! Y
//!
//! Introduce a hash
//!
//! d0054fddab35b4aa7ab1356811f5c5ef7a1536ccca1ac76549b36030c875c4329d12f86b67591e3d9b3ca7f178861c94
//!
//! 5
//!
//! r:57
//!
//! Do you want to enter another hash?[Y/N]
//!
//! N
//!
//! 110277345636720260972118701
//!
//! where the number after each hash is the value mod 31 (d) and r is a rand number that calculates the rth prime in [x,y].
//! The last number is the product of all primes. Can you find one of the primes? ;)
//!
use std::u128;
extern crate rand;
use rand::Rng;

pub fn hash_to_prime(v2: Vec<&str>) -> u128{
let mut count:u128;
let mut seed:u128;
let mut res:u128;
let mut n:u32;
n=0;
res=0;
let n3=v2.len() as u32;
for element in v2.clone(){

count=hex(element);
seed=count*u128::pow(2,(n3-1)-n);
res=(res+seed)%31;
n=n+1;
}
println!("{}", res);
if res==0{
res=31;
}
let mut x=u128::pow(2,res as u32)-1;
if x==0{
x=1;

}
let y=u128::pow(2, (res+1) as u32)-1;
let z:u128;
z=private_find_prime(x, y, r);
return z
//println!("PRIME:{}", z);

}
fn hex (a: &str) -> u128 {
let mut count:u128;
count = 0;
if a == "0"{
count = 0;
}
if a == "1"{
count = 1;
}
if a == "2"{
count = 2;
}

if a == "3"{
count = 3;
}
if a == "4"{
count = 4;
}
if a == "5"{
count = 5;
}
if a == "6"{
count = 6;
}
if a == "7"{
count = 7;
}
if a == "8"{
count = 8;
}
if a == "9"{
count = 9;
}
if a == "a" || a=="A"{
count = 10;
}
if a == "b" || a=="B"{
count = 11;
}
if a == "c" || a=="C"{
count = 12;
}
if a == "d" || a=="D"{
count = 13;
}
if a == "e" || a=="E"{
count = 14;
}
if a == "f" || a=="F"{
count = 15;
}
if a == "\0"{
count=0;
}
count
}
fn private_find_prime (x: u128, y: u128, r: u32) -> u128{
let mut n:u128;
let mut i=0;
let mut c;
let mut d:u32;
d=0;
println!("r:{}", r);
loop{
if x>=8388607{
n=x+i;
c=its_prime(n);
if c==1{

break;
}else{
i=i+1;
}
}else{
n=x+i;
c=its_prime(n);
if c==1{
d=d+1;
i=i+1;
if d==r{
break;
}
}else{
i=i+1;
}
}
}
if n==y{
n=0;
}
if x==1{
n=2;
}
n as u128
}
fn its_prime (x : u128) -> i32{
let mut coun=0;
let n;
let mut i= 3;
if x%2==0{
n=0;
return n;
}
while i < x{

if x%i == 0{
coun=coun+1;
}
i=i+2;
}
if coun == 0{
n=1;
}else{
n=0;
}
n
}
```