mirror of https://github.com/dirtbags/moth.git
Change answer hash algorithm to SHA1₄
This commit is contained in:
parent
c72d13af32
commit
f49eb3ed46
|
@ -6,8 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [v4.6.0] - unreleased
|
## [v4.6.0] - unreleased
|
||||||
### Changed
|
### Changed
|
||||||
- We are now using djb2xor instead of sha256 to hash puzzle answers
|
- Answer hashes are now the first 4 characters of the hex-encoded SHA1 digest
|
||||||
- Lots of work on the built-in theme
|
- Reworked the built-in theme
|
||||||
- [moth.mjs](theme/moth.mjs) is now the standard MOTH library for ECMAScript
|
- [moth.mjs](theme/moth.mjs) is now the standard MOTH library for ECMAScript
|
||||||
- Devel mode no longer accepts an empty team ID
|
- Devel mode no longer accepts an empty team ID
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha1"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -85,9 +85,9 @@ func (puzzle *Puzzle) computeAnswerHashes() {
|
||||||
}
|
}
|
||||||
puzzle.AnswerHashes = make([]string, len(puzzle.Answers))
|
puzzle.AnswerHashes = make([]string, len(puzzle.Answers))
|
||||||
for i, answer := range puzzle.Answers {
|
for i, answer := range puzzle.Answers {
|
||||||
sum := sha256.Sum256([]byte(answer))
|
sum := sha1.Sum([]byte(answer))
|
||||||
hexsum := fmt.Sprintf("%x", sum)
|
hexsum := fmt.Sprintf("%x", sum)
|
||||||
puzzle.AnswerHashes[i] = hexsum
|
puzzle.AnswerHashes[i] = hexsum[:4]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,12 @@ func TestPuzzle(t *testing.T) {
|
||||||
if (len(p.Answers) == 0) || (p.Answers[0] != "YAML answer") {
|
if (len(p.Answers) == 0) || (p.Answers[0] != "YAML answer") {
|
||||||
t.Error("Answers are wrong", p.Answers)
|
t.Error("Answers are wrong", p.Answers)
|
||||||
}
|
}
|
||||||
|
if len(p.Answers) != len(p.AnswerHashes) {
|
||||||
|
t.Error("Answer hashes length does not match answers length")
|
||||||
|
}
|
||||||
|
if len(p.AnswerHashes[0]) != 4 {
|
||||||
|
t.Error("Answer hash is wrong length")
|
||||||
|
}
|
||||||
if (len(p.Authors) != 3) || (p.Authors[1] != "Buster") {
|
if (len(p.Authors) != 3) || (p.Authors[1] != "Buster") {
|
||||||
t.Error("Authors are wrong", p.Authors)
|
t.Error("Authors are wrong", p.Authors)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue