Created
June 28, 2023 14:00
-
-
Save ewrvp7lv7/4e8aa40e49fe2b64630e8acd6a9b41bf to your computer and use it in GitHub Desktop.
Finding appropriate hashes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::{stdout, Write}; | |
use sha3::{Keccak256, Digest}; | |
fn main() { | |
let mut stdout = stdout(); | |
let samples: [u32; 4] = [0xbeced095, 0x42a7b7dd, 0x45e010b9, 0xa86c339e]; | |
//let samples: [u32; 4] = [0x6ca54da2, 0xfe07a987, 0x45e010b9, 0x036b6384]; | |
let mut res: [u64; 4] = [0, 0, 0, 0]; | |
let mut counter = 0u64; | |
while res.iter().any(|&item| item == 0) { | |
//while counter<300 { | |
let mut hasher = Keccak256::default(); | |
//hasher.update(format!("{counter}")); | |
let arr_tmp:[u8; 32-8] = [0;32-8]; | |
let arr_ctr =counter.to_be_bytes(); | |
let uint256 = [&arr_tmp[..], &arr_ctr[..]].concat(); | |
//[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6] | |
hasher.update(uint256); | |
let digest: [u8; 32] = hasher.finalize().into(); | |
for (i, sh) in samples.iter().enumerate() { | |
if *sh == as_u32_be(&digest){ | |
res[i] = counter; | |
println!("\r{counter}:{:x} ", as_u32_be(&digest)); | |
} | |
} | |
counter += 1; | |
if counter % 10000 == 0 { | |
print!("\rProcessing:{counter}"); | |
stdout.flush().unwrap(); | |
} | |
} | |
} | |
// Signature-Generating-Sample | |
// https://docs.next.id/developer-guide/rust | |
// https://github.com/RustCrypto/hashes | |
fn as_u32_be(array: &[u8; 32]) -> u32 { | |
((array[0] as u32) << 24) + | |
((array[1] as u32) << 16) + | |
((array[2] as u32) << 8) + | |
((array[3] as u32) << 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment