parent
c73d4db733
commit
553d93f38a
5
.idea/.gitignore
vendored
5
.idea/.gitignore
vendored
@ -1,5 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="WEB_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="JavaScriptLibraryMappings">
|
|
||||||
<includedPredefinedLibrary name="Node.js Core" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/ctf10k-rpn.iml" filepath="$PROJECT_DIR$/.idea/ctf10k-rpn.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
59
main.js
59
main.js
@ -1,59 +0,0 @@
|
|||||||
const Net = require('net');
|
|
||||||
|
|
||||||
const port = 8002
|
|
||||||
const host = "ctf10k.root-me.org"
|
|
||||||
|
|
||||||
const client = new Net.Socket
|
|
||||||
|
|
||||||
client.on('data', (data) => {
|
|
||||||
console.log("received data:\n", data.toString())
|
|
||||||
|
|
||||||
regex =/(?<equation>^\d+.*$)/m
|
|
||||||
let message = regex.exec(data.toString()).groups["equation"]
|
|
||||||
console.log("equation:", message)
|
|
||||||
|
|
||||||
let response = interpretRPN(message)
|
|
||||||
console.log("response:", response)
|
|
||||||
let buf = Buffer.from(response+"\n")
|
|
||||||
client.write(buf)
|
|
||||||
})
|
|
||||||
|
|
||||||
client.on('end', () => {
|
|
||||||
console.log("connection terminated by remote host")
|
|
||||||
})
|
|
||||||
|
|
||||||
client.connect({port: port, host: host}, () => {
|
|
||||||
console.log("connected")
|
|
||||||
})
|
|
||||||
|
|
||||||
function interpretRPN(message){
|
|
||||||
const operators = ['-', '+', 'x', '/']
|
|
||||||
let elements = message.split(' ')
|
|
||||||
for (let i = 0; i < elements.length; i++) {
|
|
||||||
if (operators.includes(elements[i])) {
|
|
||||||
let operation = elements.slice(i-2, i+1)
|
|
||||||
let result = computeOperation(operation)
|
|
||||||
elements.splice(i-2, 3, result)
|
|
||||||
i = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return elements.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
function computeOperation(operation) {
|
|
||||||
switch (operation[2]) {
|
|
||||||
case '-':
|
|
||||||
return BigInt(operation[0]) - BigInt(operation[1])
|
|
||||||
case 'x':
|
|
||||||
return BigInt(operation[0]) * BigInt(operation[1])
|
|
||||||
case '/':
|
|
||||||
return BigInt(operation[0]) / BigInt(operation[1])
|
|
||||||
case '+':
|
|
||||||
return BigInt(operation[0]) + BigInt(operation[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// const example = "994 611 + 357 733 + 82 543 - x x 740 + 136 x 996 +"
|
|
||||||
// console.log("response:", interpretRPN(example))
|
|
||||||
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "ctf10k-rpn",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"dependencies": {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user