blob: bfed16b29e7ce0b175941cd5d7e6c38a8ba7c465 (
plain) (
blame)
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
|
mod iter;
mod load_file;
mod demo_hash;
use num::BigInt;
use num::bigint::Sign;
fn vec_pop_cnt(v: &Vec<u8>) -> u32
{
let mut cnt = 0;
for x in v
{
cnt += x.count_ones();
}
cnt
}
fn pop_cnt_vec(c: u32) -> Vec<u8>
{
let mut v = Vec::new();
v.push(2u8.pow(c % 8) - 1);
for _ in 0..(c / 8)
{
v.push(0xff);
}
v
}
fn main()
{
/* "Compression" setup */
let raw_file = load_file::load_file_vec(&"data.bin".to_owned()).unwrap();
let size = raw_file.len();
let popcnt = vec_pop_cnt(&raw_file);
let bi_file = BigInt::from_bytes_be(Sign::Plus, &raw_file);
let solution_hash = demo_hash::hash_bigint(size, &bi_file);
println!("Length: {}", size);
print!("SHA512: ");
demo_hash::show_hash(&solution_hash);
println!("popcnt: {}", popcnt);
/*
// , ,
for _ in 0..1000000
{
bi = iter::next(&bi);
}
println!("{:x}", bi);
panic!("stopping after benchmark");
*/
//panic!("Performing compress only");
/* "Decompression" loop */
let raw = pop_cnt_vec(popcnt);
let mut bi = BigInt::from_bytes_be(Sign::Plus, &raw);
loop
{
let iteration_hash = demo_hash::hash_bigint(size, &bi);
//println!("{:b}", bi);
//println!();
if iteration_hash == solution_hash
{
demo_hash::show_hash(&iteration_hash);
break;
}
bi = iter::next(&bi);
}
println!("Found hash (data follows)!!!");
println!("{:x}", bi);
}
|