Skip to content

Commit

Permalink
Change answer hash algorithm to SHA1₄
Browse files Browse the repository at this point in the history
  • Loading branch information
neale-pnnl committed Sep 15, 2023
1 parent c72d13a commit f49eb3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions pkg/transpile/puzzle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bufio"
"bytes"
"context"
"crypto/sha256"
"crypto/sha1"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -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]
}
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/transpile/puzzle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit f49eb3e

Please sign in to comment.