commit a30bff8abb78d89eb590d5979d44aa02c3090659 Author: Joshua Shoemaker Date: Fri Sep 8 19:17:01 2017 -0500 Init Commit diff --git a/LOST_THE_GAME.png b/LOST_THE_GAME.png new file mode 100644 index 0000000..5b0adf4 Binary files /dev/null and b/LOST_THE_GAME.png differ diff --git a/app.js b/app.js new file mode 100644 index 0000000..ef02479 --- /dev/null +++ b/app.js @@ -0,0 +1,289 @@ +//----------Constant Values and Objects--------- +let targetIpAddress = ''; +const lockoutMax = 4; +let lockoutHits = 0; +let ipAttempts = []; +let time = 460000; +let lose = false; +let win = false; +let timerElement = document.getElementById('timer'); +let timeInterval = {}; + +const systemTypes = ["HIDDEN", "KALILINUX", "WINDOWSXP", "WINDOWS2000", + "WINDOWS10", "REDHAT", "ANDROID4.4", "NETHUNTER"]; + +const Entry = function(){ + return { + value: createIP(), + machineType: systemTypes[randomInRange(0, systemTypes.length - 1, 0)], + status: "ACTIVE", + hostName: createRandomName(), + lastResponse: randomInRange(1000, 10000000, 0), + systemLocation: { + long: randomInRange(-180, 180, 3), + lat: randomInRange(-180, 180, 3) + } + } +} + + + +//-----------Helper Functions----------- +function createIP() { + let text = ""; + let possible = "0123456789"; + + for (var i = 0; i < 10; i++) + text += possible.charAt(Math.floor(Math.random() * possible.length)); + + return text; +} + + +function formatIP(ip){ + let newIP = ip; + + newIP = newIP.slice(0, 2) + '.' + newIP.slice(2); + newIP = newIP.slice(0, 6) + '.' + newIP.slice(6); + newIP = newIP.slice(0, 9) + '.' + newIP.slice(9); + + return newIP; +} + + +function randomInRange(min, max, fixed){ + return (Math.random() * (max - min) + min).toFixed(fixed) * 1; +} + + +function createEntryHTML(entry){ + + let {value, status, machineType, hostName, lastResponse, systemLocation} = entry; + let ipAddress = formatIP(value); + let htmlString = "\ + \ + \ + "+ formatIP(value) +"\ + "+ status +"\ + "+ hostName +"\ + "+ machineType +"\ + "+ lastResponse +"MS\ + "+ systemLocation.long + "-" + systemLocation.lat +"\ + \ + " + + return htmlString; + +} + +function createEntryHTMLArray(entries){ + + let htmlStrings = []; + + entries.forEach(function(e) { + htmlStrings.push(createEntryHTML(e)); + }, this); + + return htmlStrings; +} + + +function createRandomName(){ + let text = ""; + let possible = "0123456789QWERTYUIOP_-ASDFGHJKLZXCVBNM"; + + for (var i = 0; i < 10; i++) + text += possible.charAt(Math.floor(Math.random() * possible.length)); + + return text; +} + + +function createEntryArray(){ + + let entries = []; + + for(i = 0; i < 27; i++){ + entries.push(new Entry()); + } + + return entries; +} + + +function concatEntryHTMLArray(entries){ + + let htmlString = ""; + + entries.forEach(function(e) { + htmlString += e; + }, this); + + return htmlString; +} + + +function renderEntries(htmlString){ + document.getElementById('entry_table').innerHTML = htmlString; +} + + +function extractIpAddressFromElement(element){ + ipAddress = element.getAttribute('data-ip-value'); + return ipAddress; +} + + +function selectTargetIpAddress(entries){ + let value = entries[randomInRange(0, entries.length - 1, 0)].value; + return value; +} + + +function compareIpAddress(value){ + let levDis = new Levenshtein(value, targetIpAddress); + let similarCount = 10 - levDis.distance; + return similarCount; +} + + + +//----------Business Logic-------- + +function init(){ + let entryArray = createEntryArray(); + let htmlArray = createEntryHTMLArray(entryArray); + let entryHTMLString = concatEntryHTMLArray(htmlArray); + let entryElements = document.getElementsByClassName('entry'); + + targetIpAddress = selectTargetIpAddress(entryArray); + renderEntries(entryHTMLString); + assignClickEvent(entryElements); + timeInterval = setInterval(countDown, 10); + + console.log(targetIpAddress); + +} + + +function assignClickEvent(elements){ + + for(i = 0; i < elements.length; i++){ + let entry = elements[i]; + entry.onclick = function(){ + clickedEntry(entry); + } + } +} + + +function clickedEntry(entry){ + + if(!lose && !win){ + let ipDifference = compareIpAddress(extractIpAddressFromElement(entry)); + + if(ipDifference === 10){ + targetIpAddressFound(entry); + renderSuccessPrecentage(100) + } + else{ + wrongEntrySelected(entry, ipDifference); + renderLockout(); + renderSuccessPrecentage(ipDifference * 10); + checkStatus(); + } +} +} + + +function targetIpAddressFound(entry){ + gameWin(); +} + + +function wrongEntrySelected(entry, similarity){ + let value = extractIpAddressFromElement(entry); + + lockoutHits = lockoutHits + 1; + saveAttempt(value); + renderAttempts(); + + + console.log(value + " was incorrect. Tries left: " + (lockoutMax - lockoutHits)); + console.log(similarity + " characters were correct. Try Again!") +} + +function renderSuccessPrecentage(percentage){ + let successPercentage = document.getElementById('precentage'); + successPercentage.innerHTML = percentage + "%"; + +} + + +function renderLockout(){ + let lockoutElement = document.getElementById('lockout'); + + lockoutElement.innerHTML = ''; + + for(i = 0; i < lockoutHits; i++){ + lockoutElement.innerHTML = lockoutElement.innerHTML + " X "; + } +} + + +function saveAttempt(value){ + ipAttempts.push(value); +} + + +function renderAttempts(){ + let attemptsTable = document.getElementById('attempts_table'); + attemptsTable.innerHTML = ""; + + ipAttempts.forEach(function(e) { + attemptsTable.innerHTML += "" + formatIP(e) + "\ + " + compareIpAddress(e) + " similar chars" + }, this); +} + +function checkStatus(){ + if(lockoutHits >= lockoutMax){ + gameLose(); + } +} + + +function gameLose(){ + let entryElements = document.getElementsByClassName('entry'); + let entryArray = []; + + lose = true; + + timerElement.innerHTML = 0; + clearInterval(timeInterval); + + Array.prototype.forEach.call(entryElements, function(e) { + e.className = "entry error" + }, this); +} + +function gameWin(){ + let targetElement = document.querySelector('[data-ip-value="' + targetIpAddress + '"]') + + win = true; + targetElement.className = "win"; + clearInterval(timeInterval); + timerElement.innerHTML = 0; +} + +function countDown(){ + if(time > 0 && !lose){ + time -= 10; + timerElement.innerHTML = time; + } + else{ + gameLose(); + } +} + +init(); diff --git a/index.html b/index.html new file mode 100644 index 0000000..5234fea --- /dev/null +++ b/index.html @@ -0,0 +1,75 @@ + + + + + Lost + + + + + + +
+

DISPLAY REPORT

+
+ +
+

TRACKING SUCCESS:

+

QUERY:

+
+ +
+

BRUTE FORCE LOCKOUT:

+

TIME LOCKOUT: MS

+
+
+ +
+ +
+ + + + + + + + + + + + + + + + +
IP ADDRESSACTIVEHOST_NAMEMACHINE_TYPELAST_RESPONCESYSTEM_LOCATION
+
+ +
+ +
+ + + + + + + + + +
ATTEMPTSSHARED CHARS
+
+ +
+ + + + + + + + + + + \ No newline at end of file diff --git a/levenshtein.js b/levenshtein.js new file mode 100644 index 0000000..77e3924 --- /dev/null +++ b/levenshtein.js @@ -0,0 +1,106 @@ +(function(root, factory){ + if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { + define(function(){ + return factory(root); + }); + } else if (typeof module == 'object' && module && module.exports) { + module.exports = factory(root); + } else { + root.Levenshtein = factory(root); + } +}(this, function(root){ + + function forEach( array, fn ) { var i, length + i = -1 + length = array.length + while ( ++i < length ) + fn( array[ i ], i, array ) + } + + function map( array, fn ) { var result + result = Array( array.length ) + forEach( array, function ( val, i, array ) { + result[i] = fn( val, i, array ) + }) + return result + } + + function reduce( array, fn, accumulator ) { + forEach( array, function( val, i, array ) { + accumulator = fn( val, i, array ) + }) + return accumulator + } + + // Levenshtein distance + function Levenshtein( str_m, str_n ) { var previous, current, matrix + // Constructor + matrix = this._matrix = [] + + // Sanity checks + if ( str_m == str_n ) + return this.distance = 0 + else if ( str_m == '' ) + return this.distance = str_n.length + else if ( str_n == '' ) + return this.distance = str_m.length + else { + // Danger Will Robinson + previous = [ 0 ] + forEach( str_m, function( v, i ) { i++, previous[ i ] = i } ) + + matrix[0] = previous + forEach( str_n, function( n_val, n_idx ) { + current = [ ++n_idx ] + forEach( str_m, function( m_val, m_idx ) { + m_idx++ + if ( str_m.charAt( m_idx - 1 ) == str_n.charAt( n_idx - 1 ) ) + current[ m_idx ] = previous[ m_idx - 1 ] + else + current[ m_idx ] = Math.min + ( previous[ m_idx ] + 1 // Deletion + , current[ m_idx - 1 ] + 1 // Insertion + , previous[ m_idx - 1 ] + 1 // Subtraction + ) + }) + previous = current + matrix[ matrix.length ] = previous + }) + + return this.distance = current[ current.length - 1 ] + } + } + + Levenshtein.prototype.toString = Levenshtein.prototype.inspect = function inspect ( no_print ) { var matrix, max, buff, sep, rows + matrix = this.getMatrix() + max = reduce( matrix,function( m, o ) { + return Math.max( m, reduce( o, Math.max, 0 ) ) + }, 0 ) + buff = Array( ( max + '' ).length ).join( ' ' ) + + sep = [] + while ( sep.length < (matrix[0] && matrix[0].length || 0) ) + sep[ sep.length ] = Array( buff.length + 1 ).join( '-' ) + sep = sep.join( '-+' ) + '-' + + rows = map( matrix, function( row ) { var cells + cells = map( row, function( cell ) { + return ( buff + cell ).slice( - buff.length ) + }) + return cells.join( ' |' ) + ' ' + }) + + return rows.join( "\n" + sep + "\n" ) + } + + Levenshtein.prototype.getMatrix = function () { + return this._matrix.slice() + } + + Levenshtein.prototype.valueOf = function() { + return this.distance + } + + return Levenshtein + +})); diff --git a/lost_the_game_UI.xd b/lost_the_game_UI.xd new file mode 100644 index 0000000..57a33d5 Binary files /dev/null and b/lost_the_game_UI.xd differ diff --git a/style.css b/style.css new file mode 100644 index 0000000..12d5c19 --- /dev/null +++ b/style.css @@ -0,0 +1,113 @@ +.screen{ + width: 900px; + height: 800px; + margin: 30px auto; + border-color: #00FF00; + border-width: 1px; + border-style: solid; + border-radius: 26px; + background-color: black; + color: white; + font-family: monospace; + overflow: hidden; +} + +#title{ + text-align: center; +} + +.green{ + color: #00FF00; +} + +.error{ + background-color: red; + color: white; +} + +.win{ + background-color: white; + color: #00FF00; +} + +.win :hover{ + background-color: white; + color: #00FF00; +} + +.score-wrapper{ + padding: 5px; +} + +.score-wrapper h3{ + margin: 0px; +} + +.score-wrapper .left{ + float: left; + width: 50%; + margin: 0px; +} + +.score-wrapper .right{ + float: right; + width: 50%; + margin: 0px; +} + +hr{ + border-color: #00ff00; + margin: 6px 0px; +} + +table{ + width: 900px; + font-size: 14px; +} + +th{ + text-align: left; + padding: 0px 4px; +} + +td{ + padding: 0px 4px; + overflow: hidden; +} + +.column-titles{ + margin-bottom: 2px; +} + +#play-wrapper{ + padding:0px 2px; + margin: 0px; +} + +.column{ + padding: 0px 1px; + overflow: hidden; + margin: 0px; +} + + + +.address-choice{ + margin: 0px; + padding: 0px; +} + +.address-choice span{ + overflow: hidden; + display: inline-block; +} + +.entry:hover{ + color: black; + background-color: #00ff00; + cursor: pointer; +} + +.lockoutMark{ + display: inline; +} \ No newline at end of file