Skip to content

Commit

Permalink
BUG: Lorem prefix for vigenere breaks last lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-ion committed Jan 7, 2025
1 parent 8f9599d commit 27790ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 7 additions & 4 deletions trainingportal/qna.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ if(!util.isNullOrUndefined(process.env.CHALLENGE_MASTER_SALT)){
masterSalt=process.env.CHALLENGE_MASTER_SALT;
}

let getSecretText = () => {
let getSecretText = (challengeId) => {
let min = 0;
let max = dictionary.length - 1;
secretText = "";
if(challengeId === "crypto_vigenere"){
secretText = "LOREM ";
}

for(let i=0;i<SECRET_WORD_COUNT;i++){
let index = util.getRandomInt(min,max);
secretText += dictionary[index];
Expand All @@ -36,7 +40,7 @@ let getCode = (challengeId, message, key) => {
mes = message;
}
else{
mes = getSecretText();
mes = getSecretText(challengeId);
}

return DEFS[challengeId](mes, key);
Expand Down Expand Up @@ -79,10 +83,9 @@ let caesarEnc = (mes, key) => {
return getRes(mes, shifted);
}

let vigenereEnc = (m, key) => {
let vigenereEnc = (mes, key) => {
let keyArray = [];
let keyLen = 3;
let mes = "LOREM " + m;

if(util.isNullOrUndefined(key)){
for(let i = 0; i<keyLen; i++){
Expand Down
10 changes: 9 additions & 1 deletion trainingportal/test/qna.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe("qna", () => {
for(let alg in qna.DEFS){
if(alg === "crypto_analysis") continue;
let res = qna.getCode(alg,text);
if(alg === "crypto_vigenere") text = "LOREM " + text;
let check = qna.checkCode(text, res.digest);
assert(check === true, `Validation failed for correct text using ${alg}`);
}
Expand All @@ -38,6 +37,15 @@ describe("qna", () => {

});


test("crypto_analysis should return the correct key",()=>{
let text = "LOREM IPSUM DOLOR";
let expected = "cfbb636cdce11fc76cdea0eec6bd98945cc025855707121df84c62fdefcbdf30";
let res = qna.getCode("crypto_analysis",text);
let check = qna.checkCode(expected, res.digest);
assert(check === true, `Validation failed for correct text in crypto_analysis`);
});

});


Expand Down

0 comments on commit 27790ed

Please sign in to comment.