Change answer hash algorithm to SHA1₄

This commit is contained in:
Neale Pickett 2023-09-15 12:34:31 -06:00
parent c72d13af32
commit f49eb3ed46
3 changed files with 11 additions and 5 deletions

View File

@ -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

View File

@ -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]
}
}

View File

@ -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)
}