Created
April 2, 2020 19:31
-
-
Save superjojo140/e8a9dbf88a68c76cacd26ef8c5db0efa to your computer and use it in GitHub Desktop.
Captcha Solutions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let dummyInput = [ | |
"Was ergibt 28 plus 9?", | |
"Bitte addieren Sie 6 und 38.", | |
"Bitte geben Sie den ersten, vierten und fünften Buchstaben von 'JEWELL' ein.", | |
"Wie viele Buchstaben hat MADRID?", | |
"Bitte subtrahieren Sie 22 von 3.", | |
"Zählen Sie die Buchstaben: THIN", | |
"Bitte ziehen Sie 2 von 9 ab.", | |
"Was ergibt 11 minus 36?" | |
] | |
const keywords = { | |
plus: ["addieren", "plus"], | |
minus1: ["subtrahieren", "ziehen"], | |
minus2: ["minus"], | |
buchstabenAnzahlWB: ["Wie viele Buchstaben"], | |
buchstabenAnzahlZSB: ["Zählen Sie die Buchstaben"], | |
buchstabenPosition: ["Bitte geben Sie den"], | |
} | |
const positions = ["ersten", "zweiten", "dritten", "vierten", "fünften", "sechsten", "siebten", "achten", "neunten", "zehnten"]; | |
function getCase(currentInput) { | |
for (const key in keywords) { | |
if (keywords.hasOwnProperty(key)) { | |
const keywordArray = keywords[key]; | |
for (const keyword of keywordArray) { | |
if (currentInput.indexOf(keyword) >= 0) { | |
return key; | |
} | |
} | |
} | |
} | |
return undefined; | |
} | |
function getSolution(currentInput, currentCase) { | |
switch (currentCase) { | |
case "plus": | |
var numbers = currentInput.match(/\d+/g).map(Number); | |
return numbers[0] + numbers[1]; | |
break; | |
case "minus1": | |
numbers = currentInput.match(/\d+/g).map(Number); | |
return numbers[1] - numbers[0]; | |
break; | |
case "minus2": | |
numbers = currentInput.match(/\d+/g).map(Number); | |
return numbers[0] - numbers[1]; | |
break; | |
case "buchstabenAnzahlWB": | |
currentInput = currentInput.replace('W', 'w'); | |
currentInput = currentInput.replace('B', 'b'); | |
var wort = currentInput.match(/[A-Z]/g); | |
return wort.length; | |
break; | |
case "buchstabenAnzahlZSB": | |
currentInput = currentInput.replace('Z', 'z'); | |
currentInput = currentInput.replace('S', 's'); | |
currentInput = currentInput.replace('B', 'b'); | |
var wort = currentInput.match(/[A-Z]/g); | |
return wort.length; | |
break; | |
case "buchstabenPosition": | |
currentInput = currentInput.replace('B', 'b'); | |
currentInput = currentInput.replace('S', 's'); | |
currentInput = currentInput.replace('B', 'b'); | |
var wort = currentInput.match(/[A-Z]/g); | |
wort = wort.join(""); | |
const bst = []; | |
for (const index in positions) { | |
const element = positions[index]; | |
if(currentInput.indexOf(element) >= 0){ | |
bst.push(wort.charAt(index)); | |
} | |
} | |
return bst.join(""); | |
break; | |
} | |
} | |
function showSol(){ | |
const test = document.getElementById("inp").value; | |
document.getElementById("out").innerHTML = getSolution(test, getCase(test)); | |
} | |
function test() { | |
for (const test of dummyInput) { | |
console.log(`Input: "${test}"`); | |
//console.log(`Case: ${getCase(test)}`); | |
console.log(`Solution: ${getSolution(test, getCase(test))}\n`); | |
} | |
} | |
test(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="captcha.js"></script> | |
<input type="text" id="inp" placeholder="Input Captcha"> | |
<button onclick="showSol()">Lösen</button> | |
<div id="out"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment