Skip to content

Commit

Permalink
Enhance anti-cheating logic (#1734)
Browse files Browse the repository at this point in the history
## Summary:
Adding logic to make cheating more difficult to implement.

Issue: LEMS-2503

Author: mark-fitzgerald

Reviewers: Myranae

Required Reviewers:

Approved By: Myranae

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1734
  • Loading branch information
mark-fitzgerald authored Oct 8, 2024
1 parent 74ba298 commit 92c4e62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-panthers-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Fix to account for recent cheat attempts
12 changes: 8 additions & 4 deletions packages/perseus/src/util/parse-perseus-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ export function parsePerseusItem(json: string): PerseusItem {
throw new Error("Something went wrong.");
}

function buildRandomString() {
function buildRandomString(capitalize: boolean = false) {
let randomString: string = "";
const randomLength = Math.floor(Math.random() * 8) + 3;
for (let i = 0; i < randomLength; i++) {
const randomLetter = String.fromCharCode(
97 + Math.floor(Math.random() * 26),
);
randomString += randomLetter;
randomString +=
capitalize && i === 0 ? randomLetter.toUpperCase() : randomLetter;
}
return randomString;
}
Expand All @@ -88,9 +89,12 @@ function buildRandomPhrase() {
const phrases: string[] = [];
const randomLength = Math.floor(Math.random() * 10) + 5;
for (let i = 0; i < randomLength; i++) {
phrases.push(buildRandomString());
phrases.push(buildRandomString(i === 0));
}
return phrases.join(" ");
const modifierStart = ["**", "$"];
const modifierEnd = ["**", "$"];
const modifierIndex = Math.floor(Math.random() * modifierStart.length);
return `${modifierStart[modifierIndex]}${phrases.join(" ")}${modifierEnd[modifierIndex]}`;
}

function buildTestData(testObject: string) {
Expand Down

0 comments on commit 92c4e62

Please sign in to comment.