-
You are right. But this is actually not a problem if the data is 100% random, because the chance that the message is "Attack from the north" is the same as "Attack from the south", or "I like cats so much!!"
But your key can be very large! You could pick different or random indexes from the key. Maybe that's a solution.
Or come up with something else. -
Is XOR Encryption with the One-Time pad an option for you?
If the key you use is random, this encryption will be uncrack-able.
And the encrypted message isn't longer then the not-encrypted message.Here's some pseudo-code:
var key = <random data> var message; function encryptMessage() { message ^= key; } function decryptMessage() { message ^= key; }
-
I'm having the same problem here: The current random generator is based on the state of the machine and time. If you disconnect the power and reconnect it again, the number sequence will be the same, which is for some usages not suitable.
I've thought about fixes for it: Adding a number of how many times it has booted or analog reading something unused(getting random noise).
I'm not a RNG expert thought, but randomness should always be unpredictable. -
-
So I'm still enjoying to work on my fruitmachine, but the way I implement multiple timeouts don't seem to work correctly.
Basically, I've 3 LED's, or fruits - or wheels, and I stop them one by one in order of time. When I spin the wheel, I tell it when to stop spinning. It works by just setting the velocity of the wheel to 0.Wheel.prototype.spin = function(stopt) // stopt = stoptime { this.vel = (2 + Math.random() * 5) / 40; // give the wheel a velocity setTimeout(this.stop, stopt); // tell it when to stop };
Then you have the
stop
functionWheel.prototype.stop = function() { this.vel = 0.0; };
The spinning happens when the user clicks the button. At that time,
spin
is called(notWheel.spin
)function spin() { for (var i = 0; i < N_LEDS;) // loop trough all wheels, spin them { wheels[i].spin((++i * 500)); } setTimeout(function(){ //... other code. It checks some win conditions and lights and stuff after every wheel stopped. }, (N_LEDS + 2.5) * 500);
But, only the last
setTimeout
seems to be called.
What am I doing wrong?Here's the full code.
-
-
-
So I decided to make a fruitmachine(but not according to the tutorial) and I'm struggling with some weird timing behavior.
Basically, when I save my code, disconnect, unplug the power, plug the power back in OR when I re-upload my code, the timing is incorrect.
I can fix it by resetting the Pico(Not justreset()
, two seconds of button pressing), and then upload the code again.
It also doesn't respond to my watches.Watch it here
The first gif is the normal way, 50% on, 50% off like in the code. The second gif the timing division is weird but consistent(when the camera shakes that's when the gif jumps to its end, so skip that)How can I fix this?
EDIT: woops forgot the code (m
This is all the code, so it may contain irrelevant code, but I'm sure all relevant is there since it's all so that's why I paste it all.EDIT 2: If I connect it again and I want to upload the code, I get these errors:
I practically can't do anything.Here's the code:
var N_LEDS = 3; var BRIGHTNESS_FACTOR = 20; var arr = new Uint8ClampedArray(N_LEDS * 3/*3 leds * 3 channels*/); SPI2.setup({baud:3200000, mosi:B15}); // Setup external button pinMode(B1, "input_pulldown"); analogWrite(A7, 1); var preflashstate = false; function preFlash() { preflashstate = !preflashstate; if (preflashstate === true) { setAll(new Color(255, 255, 0)); } else { setAll(new Color(0, 0, 0)); } updateLeds(); } function LED2Flash() { LED2.write(!LED2.read()); } function updateLeds() { var col = new Uint8ClampedArray(arr.length); for (var i = 0; i < arr.length; i++) { col[i] = arr[i] / BRIGHTNESS_FACTOR; } SPI2.send4bit(col, 0b0001, 0b0011); } function clearAll() { for (var i = 0; i < arr.length; i++) { arr[i] = 0; } } function setAll(color) { for (var i = 0; i < N_LEDS; i++) { color.setToLed(i); } } var Color = function(r,g,b) { this.r = r; this.g = g; this.b = b; }; Color.prototype.setToLed = function(led) { led *= 3; //arr.splice(led, 3, this.r, this.g, this.b); arr[led ] = this.r; arr[led + 1] = this.g; arr[led + 2] = this.b; }; var SlotType = function(name, prize, color) { this.name = name; this.prize = prize; this.color = color; }; var Wheel = function(index) { this.i = index; }; var SYMBOLS = [ new SlotType("Cherry", 20, new Color(255, 0, 0)), new SlotType("Lemon", 50, new Color(255, 255, 0)), new SlotType("Melon", 100, new Color(0, 153, 51)), new SlotType("7", 200, new Color(255, 2, 120)), new SlotType("Bar", 500, new Color(0, 255, 255)), ]; function reset() { clearInterval(); clearWatch(); init(); } function init() { setInterval(preFlash, 700, {repeat:true}); setInterval(LED2Flash, 250, {repeat:true}); setWatch(function(){ clearInterval(); clearWatch(); clearAll(); preflashstate = false; LED2.write(0); updateLeds(); setWatch(reset, BTN, {repeat:true}); }, B1, {repeat:true,edge:"rising"}); } init();
-
I like to do stuff
http://joppiesaus.function1.nl/
Yes
You don't even need to power it via the USB, you could also power it by connecting it to BAT_IN and the GND pin(the two front pins), as long as the input voltage is ≥ 3.5 & ≤ 16v!