暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

main.rs 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. extern crate clap;
  2. extern crate time;
  3. use time::get_time;
  4. use clap::{Arg, App, SubCommand};
  5. use std::process;
  6. mod hasher_sha256;
  7. mod hash256;
  8. pub fn main() {
  9. let matches = create_app().get_matches();
  10. let base = matches.value_of("base").unwrap_or("1");
  11. let diff = matches.value_of("difficulty").unwrap_or("1");
  12. let mut time_measurement = false;
  13. if diff.chars().any( |c| !c.is_digit(16)) {
  14. println!("Difficulty is not hexadecimal.");
  15. process::exit(1)
  16. }
  17. if let Some(ref sub_command) = matches.subcommand {
  18. if sub_command.name.eq("timings") {
  19. time_measurement = true;
  20. }
  21. }
  22. match base.parse::<usize>() {
  23. Ok(b) => {
  24. println!("Using base: {}", base);
  25. println!("Using difficulty: {}", diff);
  26. println!("Please wait...");
  27. let start = get_time();
  28. let max = <usize>::max_value();
  29. for n in 0..max {
  30. if let Some(x) = hash256::verify_product(b, n, &diff.to_string()) {
  31. let end = get_time();
  32. println!("Number: {} --> hash: {}", x.number, x.hash);
  33. if time_measurement{
  34. let diff = end - start;
  35. let s = diff.num_seconds();
  36. let ms = diff.num_milliseconds();
  37. let us = diff.num_microseconds().unwrap_or(ms * 1000);
  38. println!("(Duration {}s / {}ms / {}us)", s, ms, us);
  39. }
  40. process::exit(0)
  41. }
  42. }
  43. }
  44. Err(_) => {
  45. println!("Base is not integer.");
  46. process::exit(1)
  47. }
  48. };
  49. }
  50. fn create_app<'a, 'b>() -> App<'a, 'b> {
  51. App::new("Hash256")
  52. .version("1.0")
  53. .author("Lorenz Bung & Joshua Rutschmann")
  54. .about("Calculates the Hashvalue of the given base, number and difficulty.")
  55. .arg(Arg::with_name("base")
  56. .value_name("base")
  57. .help("The base of the hash to be calculated on.")
  58. .takes_value(true)
  59. .required(true))
  60. .arg(Arg::with_name("difficulty")
  61. .value_name("difficulty")
  62. .help("The difficulty of the calculated hash.")
  63. .takes_value(true)
  64. .required(true))
  65. .subcommand(SubCommand::with_name("timings")
  66. .about("controls timing features")
  67. .version("1.0")
  68. .author("Lorenz Bung & Joshua Rutschmann"))
  69. }