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
|
||||
### Changed
|
||||
- We are now using djb2xor instead of sha256 to hash puzzle answers
|
||||
- Lots of work on the built-in theme
|
||||
- Answer hashes are now the first 4 characters of the hex-encoded SHA1 digest
|
||||
- Reworked the built-in theme
|
||||
- [moth.mjs](theme/moth.mjs) is now the standard MOTH library for ECMAScript
|
||||
- Devel mode no longer accepts an empty team ID
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"crypto/sha1"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -85,9 +85,9 @@ func (puzzle *Puzzle) computeAnswerHashes() {
|
|||
}
|
||||
puzzle.AnswerHashes = make([]string, len(puzzle.Answers))
|
||||
for i, answer := range puzzle.Answers {
|
||||
sum := sha256.Sum256([]byte(answer))
|
||||
sum := sha1.Sum([]byte(answer))
|
||||
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") {
|
||||
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") {
|
||||
t.Error("Authors are wrong", p.Authors)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue