Skip to content

Instantly share code, notes, and snippets.

@theomessin
Last active January 16, 2019 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theomessin/c6b32bfb2f9cef11c8c8cfbaa7db049b to your computer and use it in GitHub Desktop.
Save theomessin/c6b32bfb2f9cef11c8c8cfbaa7db049b to your computer and use it in GitHub Desktop.
Solution to a job application quiz.
#include <iostream>
using namespace std;
int main() {
int a = 18, b = 43, c = -14;
int cipher[] = {90,144,94,126,154,30,50,110,97,128,146,100,115,159,103,126,140,102,123,154,96,133,75,88,129,157,18,133,154,94,136,148,96,121,75,102,122,144,18,89,140,95,116,148,102,50,142,90,115,151,94,119,153,89,119,89,18,98,151,87,115,158,87,50,158,87,128,143,18,139,154,103,132,75,101,129,151,103,134,148,97,128,75,83,128,143,18,85,129,18,134,154,18,123,142,83,128,142,97,118,144,50,121,140,95,116,148,102,132,144,101,119,140,100,117,147,32,117,154,95,50,156,103,129,159,91,128,146,18,132,144,88,119,157,87,128,142,87,76,75,86,75,144,84,119,141,38,68,144,39,64};
int size = 151;
char message[size];
for (int i = 0 ; i < size ; i++) {
if (i % 3 == 0) cipher[i] -= a;
if (i % 3 == 1) cipher[i] -= b;
if (i % 3 == 2) cipher[i] -= c;
message[i] = cipher[i];
}
cout << message;
return 0;
}
let ciphertext = document.getElementsByTagName("html")[0].innerText.substr(66).split(" ");
let a = 72 - ciphertext[0]; //Assume first char H
let b = 101 - ciphertext[1]; // Assume first char e
let c = 108 - ciphertext[2]; // Assume first char l
ciphertext = ciphertext.map( (x, i) => {
x = parseInt(x);
let code;
switch(i % 3) {
case 0:
code = x + a;
break;
case 1:
code = x + b;
break;
case 2:
code = x + c;
break;
}
return String.fromCharCode(code % 256);
});
alert(ciphertext.join(""));

Here's how I solved a Job Application Quiz.

First thing I did was inspect the quiz page. I found that there was a piece of code that wasn't really supposed to be there. It was not being executed and I took that as a hint:

function(ascii,a,b,c) {
	for(i=0;i<ascii.length;i++) {
		if(i%3==0){ascii[i]=(ascii[i]+a)%256;}
		if(i%3==1){ascii[i]=(ascii[i]+b)%256;}
		if(i%3==2){ascii[i]=(ascii[i]+c)%256;}
	}
	return ascii;
}

This code indicates that the cipher text is simply a shift cipher of the message where the shift factor varries every three characters.

Next thing I did was assume that the last character would be a period. Knowing that a period has an ASCII code of 46, I found the a shift factor required to get that. Then I found that with that assumption, the text would start with H**l**. I assumed that it would start with Hel for Hello. Thus I was able to calculate the required b and c shift factors.

Then, reverse engineering the code provided, I found that the message was:

Hello, Congratulations for solving the XXXXXX challenge. Please send your solution and CV to icancode@XXXXXXXXXXXXXX.com quoting reference: fea57fca2d.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment