Procházet zdrojové kódy

Fixed some compiling errors, still doesn't work -_-

Lorenz Bung před 8 roky
rodič
revize
8b8664f737
2 změnil soubory, kde provedl 12 přidání a 3 odebrání
  1. 1
    0
      hw7/task1/Cargo.toml
  2. 11
    3
      hw7/task1/src/hash256.rs

+ 1
- 0
hw7/task1/Cargo.toml Zobrazit soubor

@@ -4,3 +4,4 @@ version = "0.1.0"
4 4
 authors = ["Lorenz Bung <lorenz.bung@googlemail.com>"]
5 5
 
6 6
 [dependencies]
7
+sha2 = "0.7.0"

+ 11
- 3
hw7/task1/src/hash256.rs Zobrazit soubor

@@ -1,5 +1,13 @@
1
-mod hasher_sha256
1
+use hasher_sha256;
2 2
 
3
-pub fn verify_product(base: usize, number: usize, difficulty: String) -> Option {
4
-    hasher_sha256::hash(base * number)
3
+struct Solution {
4
+    number: usize,
5
+    hash: String,
6
+}
7
+
8
+pub fn verify_product(base: usize, number: usize, difficulty: String) -> Option<Solution> {
9
+    if let x = hasher_sha256::Hasher::hash(i32::from(base * number).as_bytes().hex().ends_with(difficulty)) {
10
+        Some(Solution{ number: (base * number), hash: x,});
11
+    }
12
+    None
5 13
 }

Loading…
Zrušit
Uložit