Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Predict the next output of a process which can only output binary states.
Predict the next output of a process which can only output binary states.
If a process outputs only two states (random or predictable), it's sometimes useful to predict the next state the process would output.
Why?
Here is a usage application:
function isAwesome(input) {
if (expensiveComputation(input))
return true;
if (expensiveOperation(input))
return true;
return false;
}
// can potentially reduce potential computations by predicting which algorithm would hit first
function betterIsAwesome(input) {
var order = foresight.guess();
var algorithms = [expensiveComputation, expensiveOperation];
var n = 2;
if (order === 'algo1') {
while(n-- > 0) {
if(algorithms[1-n](input)) {
(n == 1) && foresight.move('algo1') || foresight.move('algo2');
return true;
}
}
} else {
while(n-- > 0) {
if(algorithms[n](input)) {
(n == 1) && foresight.move('algo2') || foresight.move('algo1');
return true;
}
}
}
return false;
}
$ npm install --save foresight
var foresightMaker = require('foresight');
var foresight = foresightMaker();
foresight.move('head');
var guess = foresight.guess();
A factory function that returns an instance of foresight
object.
Type: object
By default foresight
uses coin-flipping semantics to capture actual moves and to predict the next move.
You may remap these values to something else. Once they're remapped, you must use the new values for foresight.move(actual)
. And as well as expect them as output of foresight.guess()
.
Example:
options.move = {
head: 'left',
tail: 'right'
}
Default:
options.move = {
head: 'head',
tail: 'tail',
pass: 'pass'
}
Input the actual state output of the tracking process.
Value: head
, tail
, or values mapped to head
and tail
.
NOTE: actual
may not equal to pass
(in default move semantics) or move mapped to pass
. Only foresight
may return pass
; which indicates that it is uncertain of its guess.
Returns a guess of the next state that a process would output.
If foresight
is uncertain of the next move, it would output pass
(or remapped value of pass
).
Otherwise, if foresight
is certain of the next move, it would output head
or tail
(or remapped values).
Code is ported to a usable npm module from: http://www.loper-os.org/bad-at-entropy/manmach.html
I did not come up with the underlying algorithm. I just rewrapped it into nicer API.
As demonstrated by someone, the algorithm is deterministic, and one can beat it. You should expect that the process you're tracking won't likely output the precise sequences of moves that foresight
would guess incorrectly most of the time.
The algorithm is light enough to be used in favour of a PRNG
in some applications. Especially when heavyweight prediction tools isn't a likely solution.
MIT
FAQs
Predict the next output of a process which can only output binary states.
We found that foresight demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.