diff --git a/src/emulator/commands/su.js b/src/emulator/commands/su.js index 6c4eabe..af5143d 100644 --- a/src/emulator/commands/su.js +++ b/src/emulator/commands/su.js @@ -1,4 +1,5 @@ const { Terminal } = require("xterm"); +const sleep = require("../../lib/sleep"); /** * @param {string[]} argv @@ -25,7 +26,37 @@ module.exports = async (argv, terminal, zsh) => { } terminal.write('Password: '); + /** @type {string} */ const pass = await zsh.get_stdin({hide: true}); + const some_random_array = new Uint16Array([12319, 14486, 12589, 13232]); + let checksum = new Uint32Array(pass.length); - terminal.write(pass); + let i = 0; + for (const letter of pass) { + checksum[i] = letter.charCodeAt(0) * 128; + checksum[i] += (i*8) - letter.charCodeAt(0); + i++; + } + i = undefined; + + console.log(checksum, some_random_array); + + let valid = true; + if (checksum.length == some_random_array.length) + for (let i = 0; i != some_random_array.length; i++) { + if (checksum[i] != some_random_array[i]) + valid = false; + } + else + valid = false; + + console.log(valid); + + if (valid) { + terminal.writeln('yay, you did it!! congratulations :3'); + } else { + await sleep(3000); + terminal.writeln('su: Authentication failure'); + return 1; + } } \ No newline at end of file