From the sublime to the ridiculous.
02/28/2022 - How snow do you go?
Discussing snow with the Snoqualmie Pass WSDOT account on Twitter - the passes appear to clear and wet, but avalanche risk keeps them closed. They just had a big slide fall on the road:
And this seems like a good opportunity to make a calculator:
Width (ft):Length (ft):
Depth (ft):
Cubic Ft:
Lbs:
KG:
02/27/2022 - New video series.
Creating videos from the historical compendium. Going for 1 video per "page", which averages a little short of 3 minutes.
Daily uploads will give a good cadence, and these are easy to make. I tested with individual entries, but this was too many videos that were too short, and was spammy in my subscriptions.
02/25/2022 - Calories burned walking 1 mile.
Data from some random health site and reformatted into a sortable table.
| Lbs | KG | Calories | MPH | Modifier |
|---|---|---|---|---|
| 130 | 147 | 2 | stroller | |
| 130 | 195 | 3 | ||
| 130 | 224 | 3.5 | ||
| 150 | 90 | 2 | ||
| 155 | 176 | 2 | stroller | |
| 155 | 232 | 3 | ||
| 155 | 267 | 3.5 | ||
| 180 | 204 | 2 | stroller | |
| 180 | 270 | 3 | ||
| 180 | 311 | 3.5 | ||
| 200 | 120 | 2 | ||
| 205 | 232 | 2 | stroller | |
| 205 | 307 | 3 | ||
| 205 | 354 | 3.5 | ||
| 250 | 150 | 2 | ||
| 300 | 180 | 2 | ||
| 350 | 210 | 2 | ||
| 400 | 240 | 2 |
The site apparently believes people over 250 lbs cannot walk more than 2 mph, as this data is not provided.
02/24/2022 - Propagation as described with Minecraft lighting.
Consider 3 parallel hallways in an older version of Minecraft, separated by 1 block, with Jack O'Lanterns as light sources. Key:
- Wall: No illumination.
- 15: Light source
- 14: 1 block from light source
- 13: 2 blocks from light source
- 12: 3 blocks from light source
- 11: 4 blocks from light source
- 10: 5 blocks from light source, illumination getting low
- 8 or 9: Illumination barely high enough to prevent monster spawn.
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 |
11 | 12 | 13 | 14 | 15 | 14 | 13 | 12 | 11 | 11 | 12 | 13 | 14 | 15 | |
2 |
10 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | 12 | 11 | 12 | 13 | |||
3 |
9 | 10 | 11 | 12 | 12 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | |||
4 |
8 | 9 | 10 | 11 | 11 | 12 | 13 | 14 | 15 | 14 | 13 | 12 | 11 | ||
5 |
9 | 10 | 11 | 12 | 12 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | |||
6 |
10 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | 12 | 11 | 12 | 13 | |||
7 |
11 | 12 | 13 | 14 | 15 | 14 | 13 | 12 | 11 | 11 | 12 | 13 | 14 | 15 | |
8 |
10 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | 12 | 11 | 12 | 13 | |||
9 |
9 | 10 | 11 | 12 | 12 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | |||
10 |
8 | 9 | 10 | 11 | 11 | 12 | 13 | 14 | 15 | 14 | 13 | 12 | 11 | ||
11 |
9 | 10 | 11 | 12 | 12 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | |||
12 |
10 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | 12 | 11 | 12 | 13 | |||
13 |
11 | 12 | 13 | 14 | 15 | 14 | 13 | 12 | 11 | 11 | 12 | 13 | 14 | 15 | |
14 |
10 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | 12 | 11 | 12 | 13 | |||
15 |
9 | 10 | 11 | 12 | 12 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | |||
16 |
8 | 9 | 10 | 11 | 11 | 12 | 13 | 14 | 15 | 14 | 13 | 12 | 11 | ||
17 |
9 | 10 | 11 | 12 | 12 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | |||
18 |
10 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | 12 | 11 | 12 | 13 | |||
19 |
11 | 12 | 13 | 14 | 15 | 14 | 13 | 12 | 11 | 11 | 12 | 13 | 14 | 15 | |
20 |
10 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | 12 | 11 | 12 | 13 | |||
21 |
9 | 10 | 11 | 12 | 12 | 11 | 12 | 13 | 13 | 12 | 11 | 12 | |||
22 |
8 | 9 | 10 | 11 | 11 | 12 | 13 | 14 | 15 | 14 | 13 | 12 | 11 |
In the above table, each open block of space gathers the brightness data from each of the 6 blocks it shares a face with, takes the Max of that, subtracts one, and sets that as its brightness value - well, the game does that to the game database, much like ETL against a SQL database. Propagation delay is where blocks will remain illuminated immediately after a light source is destroyed, as their illumination value has not been updated.
Physical effects in our universe work in much the same way, such as an electromagnetic wave travelling through space. At one point, it's an electric wave - this dissipates, but before it does, it generates a magnetic field at a right angle (90 degrees) to it. This also dissipates, but before it can it generates an electric field at an inverse right angle (270 degrees) to it. This set of generation and dissipation propagates through spacetime as a photon.
02/23/2022 - Stay Frosty.
A correction to the Phil blog entry - it snowed! We switched from the warmish drear of constant overcast and are into the chilly beauty of wintertime sunshine. So maybe other people really do understand Phil's meteorological prognostications better than I.
02/22/2022 - An Enigma, Sold by a Riddle, Built into a Mystery: Part 5 - Enigma Man.
To cap off this enigmatic journey, here is Enigma Man, a cipher which performs my Running Man cipher 9 times:
//Message://Encrypted:
//Reverted:
This cipher ran 9 times is probably more secure than the 9 ciphers in Enigma, plus no key is required, just the message. Indeed, the number of encryption rotations could be viewed as a type of key. It's more secure because adding or removing a pair of letters from the end of the message changes the entire encrypted output, since removing letters shifts the midpoint of the message, which moves the first letter of the key. A downside is that message length must be even or lose a character.
Enigma was somewhat overengineered on the encryption side, but was a nifty application-specific mechanical computer. The faulty philosophy of "nobody could reverse engineer something this overengineered" ignored Polish ingenuity.
02/21/2022 - An Enigma, Sold by a Riddle, Built into a Mystery: Part 4 - Be Kind, Rewind.
//As promised, here is a breakdown of the rewritten functions. They needed to be rewritten because Enigma isn't just a simple replace - the key advance isn't reciprocal. An error in Wheel Boogaloo is that the function still needs a revert to roll backwards the key on the other side. The wheels should go through enigmaForward on the first pass, then enigmaReverse on the second.
//enigmaForward
//This function starts much like the rest - uppercase the input string. Also grab the key array length since it's used often. These are using the keyArrays and swapArrays defined in yesterday's blog.
inputString = inputString.toUpperCase().replace(/ /g,"");
var kaLen = keyArray.length;
//Foreach letter in the message, determine the indexAdvance (Enigma's secret sauce) by dividing the index by the wheelModulus - this will be 1 (every key) for Wheel A, 26 (every alphabet) for Wheel B, and 676 (every 26 alphabets) for Wheel C. This could be extended with further wheels by multiplying the previous wheelModulus by 26. Also prepare the output variable.
-
for (index = 0;index<inputString.length;index++) {
var indexAdvance = Math.floor(index/wheelModulus);
var letterInput = inputString.substring(index,index+1);
var output = "";
//This handles the reciprocation - if it's not in the keyArray, it's in the swapArray.
-
if (keyArray.indexOf(inputString.substring(index,index+1)) == -1) {
output = keyArray[(swapArray.indexOf(letterInput) + indexAdvance)%kaLen]
else {
output = swapArray[(keyArray.indexOf(letterInput) + indexAdvance)%kaLen]
//Replace the current letter by building a new string: the old string before the current letter, the output variable, and then the old string after the current letter.
-
inputString = inputString.substring(0,index) + output + inputString.substring(index+1,inputString.length);
return inputString;
//enigmaReverse
//This function is nearly identical to enigmaForward - indeed, a quality developer likely could unify these into a single function.
inputString = inputString.toUpperCase().replace(/ /g,"");
var kaLen = keyArray.length;
for (index = 0;index<inputString.length;index++) {
//The indexAdvance here is a little more complex - it has to handle rolling backwards without providing a negative result. This equation ends with the dividing the index by the wheelModulus, but subtracted. Before that is a way of "stacking more key loops" onto the key, so there are more than enough to subtract. For Wheel A, this number will be as long as the message length, which could be hundreds or thousands of letters long.
-
var indexAdvance = (kaLen*Math.ceil(Math.floor(index/wheelModulus)/kaLen)) - Math.floor(index/wheelModulus);
var letterInput = inputString.substring(index,index+1);
var output = "";
//Same setup before and same reciprocation after. Moving the indexAdvance math up above allows for an identical section here.
-
if (keyArray.indexOf(inputString.substring(index,index+1)) == -1) {
output = keyArray[(swapArray.indexOf(letterInput) + indexAdvance )%kaLen]
else {
output = swapArray[(keyArray.indexOf(letterInput) + indexAdvance )%kaLen]
//Just as before, this section is also just as before.
-
inputString = inputString.substring(0,index) + output + inputString.substring(index+1,inputString.length);
return inputString;
//Revisiting the order of wheels will show how this is set up:
- //enigmaReciprocal Front Panel cipher
- //enigmaForward Wheel A cipher
- //enigmaForward Wheel B cipher
- //enigmaForward Wheel C cipher
- //enigmaReciprocal Hub cipher
- //enigmaReverse Wheel C cipher
- //enigmaReverse Wheel B cipher
- //enigmaReverse Wheel A cipher
- //enigmaReciprocal Front Panel cipher
This process is fully reciprocal, and the same steps perform both encryption and decryption.
02/20/2022 - An Enigma, Sold by a Riddle, Built into a Mystery: Part 3 - A Sprial Inside A Circle, A Wheel Inside A Wheel.
To stack these up, we're going to nest enigmaReciprocal inside itself 9 times, using 5 different keys:
- //Reciprocal Front Panel cipher: enigmaReciprocal using the static Front Panel keyArray and swapArray.
- //Reciprocal Wheel A cipher: enigmaReciprocal using the rotating Wheel A keyArray and swapArray.
- //Reciprocal Wheel B cipher: enigmaReciprocal using the rotating Wheel B keyArray and swapArray.
- //Reciprocal Wheel C cipher: enigmaReciprocal using the rotating Wheel C keyArray and swapArray.
- //Reciprocal Hub cipher: enigmaReciprocal using the static Hub keyArray and swapArray.
- //Reciprocal Wheel C cipher: enigmaReciprocal using the rotating Wheel C keyArray and swapArray.
- //Reciprocal Wheel B cipher: enigmaReciprocal using the rotating Wheel B keyArray and swapArray.
- //Reciprocal Wheel A cipher: enigmaReciprocal using the rotating Wheel A keyArray and swapArray.
- //Reciprocal Front Panel cipher: enigmaReciprocal using the static Front Panel keyArray and swapArray.
Arrays
Front Panel
//keyArray://swapArray:
Wheel A
//keyArray://swapArray:
Wheel B
//keyArray://swapArray:
Wheel C
//keyArray://swapArray:
Hub
//keyArray://swapArray:
Main Event
//Message://Encrypted:
//Reverted:
Rotating the keyArray and swapArray forward required rewriting the enigmaReciprocal function. Stay tuned for the function break-down and wrap-up!
02/17/2022 - Interlude - Running Man Cipher.
Using both Running Key and my Inverse Running key will encrypt both halves of a message - first the last half with the first, then the first half with the last. Err...this will encrypt the first half first, then the last half, because that's how the original function was written.
//Message://RunningKey:
//Inverse:
//Revert Inverse:
//Revert RunningKey:
02/16/2022 - An Enigma, Sold by a Riddle, Built into a Mystery: Part 2 - Wheel Boogaloo.
Proving that we need a reciprocal key with 2 scenarios: a 3 letter swap rotation, and then a 2 letter swap (reciprocal) rotation. We'll use the short message "CAT JAR", keeping the space for clarity. The same settings were used to encrypt and decrypt, so we'll take the first round's output and run it through again. The wheels are interchangeable so this applies to them all, and therefore we can use just 1 wheel to simplify our demonstration.
3 letter swap wheel
Input:
- CAT JAR
- JCB ACM
3 letter swap wheel encryption rotates A > C, C > J, then J > A. This changes 4 of the 6 letters, or 2/3 of the message. Here we can already see the decryption process failing in the lower message.
- JCT ACR
- AJB CJM
2 letter swap hub encryption reciprocally rotates M > R and R > M. This only changes the final letter.
- JCT ACM
- AJB CJR
And back through the key, this time encountering B > L, L > T, then T > B. This also only changes one letter - the first word's last letter.
- JCB ACM
- AJL CJR
As foreshadowed above, the 3 letter swap wheel failed to reciprocally decrypt its message.
2 letter swap wheel
Input:
- CAT JAR
- ACE RCJ
2 letter swap wheel encryption reciprocally rotates just A > C and C > A. This changes 3 of the 6 letters, or 1/2 of the message. Here we can see half of the original message from the encryption.
- ACT JCR
- CAE RAJ
2 letter swap hub encryption reciprocally rotates J > R and R > J. This changes 2 of the 6 letters, or 1/3 of the message. In the decryption, one word is already fully decrypted.
- ACT RCJ
- CAE JAR
2 letter swap wheel encryption reciprocally rotates just E > T and T > E. This changes 1 of the 6 letters. Decryption is successful.
- ACE RCJ
- CAT JAR
The wheel can be reciprocal because it passes through the hub before reciprocating, which makes the reciprocation run into a 3rd round of encryption. This means that each wheel can be defined in Javascript by the same enigmaReciprocal function from yesterday's post, using Porta's Alpha and Bet for the keyArray and swapArray respectively. Or the keys could be randomized - Alpha and Bet give a good starting place, since all 26 letters in the alphabet should be paired for the wheels, not just the 10 or less for the front panel.
This also means the hub can also use this same setup as the wheels. The hub keyArray and swapArray would remain static, while the wheel arrays would change daily.
Next up: Assembling all the wheels.
02/15/2022 - An Enigma, Sold by a Riddle, Built into a Mystery: Part 1 - Days of Future Past.
//The Enigma machine was a pseudo-random series of key-swap ciphers:
- //Input from keyboard
- //Reciprocal Front Panel cipher
- //Reciprocal Wheel A cipher
- //Reciprocal Wheel B cipher
- //Reciprocal Wheel C cipher
- //Reciprocal Hub cipher
- //Reciprocal Wheel C cipher
- //Reciprocal Wheel B cipher
- //Reciprocal Wheel A cipher
- //Reciprocal Front Panel cipher
- //Output to lightbulb
//The front panel resembled a telephone switchboard, and manually swapped 2 letters. This is just like running .replace(/text/g,"replacement text") on a string in Javascript, but twice and using a swap character.
/Cipher wheels A, B, and C swap 2 letters like the front panel, but this can't be changed without disassembling the wheel. The wheels were removable, and each day would have a different set of 3 wheels from the box of like 12 wheels. If you forgot to update your wheels in the morning, you'd only see scrambled messages.
- //Wheel A's index is the message index modulus 26, changing the modifier for every letter with every keypress. 27%26 = 1
- //Wheel B's index is the message index divided by 26, rounded down - changing the letter with every cycle of Wheel A. Math.floor(27/26) = 1
- //Wheel C's index is likewise message index divided by 26, rounded down, then divided by 26 and rounded down again. Math.floor(Math.floor(676/26)/26) = 1
//The Hub was very similar to the wheels, but wasn't removable.
//Then revert the process of Wheels C, B, and A - followed by reverting the front panel. This feels not unlike rotating a corner piece on a Rubick's cube - a number of setup operations to move things out of the way, one "main event" move, and a number of reversion operations to undo the setup.
//To build this in Javascript, the same function could be used foreach of the ciphers, and the reversion function could be used foreach of the reversions. Just change the input alphabet. Since this function could take up to 13 characters, the sets of characters to swap are represented by 2 equal-length arrays: keyArray and swapArray. The first letter in keyArray will swap with the first in swapArray, and so forth.
swapArray = ["P","K","Y","I","V","Z","D","S","C","X"];
function enigmaReciprocal(inputString,keyArray,swapArray){
for (index = 0;index>keyArray.length;index++) {
regexKey = new RegExp(keyArray[index],'g');
regexSwap = new RegExp(swapArray[index],'g');
inputString = inputString.replace(regexKey,'#@#');
inputString = inputString.replace(regexSwap,keyArray[index]);
inputString = inputString.replace(/#@#/g,swapArray[index]);
return inputString;
//swapArray:
//Message:
//Encrypted:
//Reverted:
//More to come tomorrow.
02/14/2022 - A microwave oven is a radar array fired into a Faraday cage.
From a homework website: "A microwave oven operates on 1500 W of power and is used for 20 minutes. How much electrical energy, in Joules and kW•h, is used by the microwave oven?"
The answer provided starts with 1 W = 1 J/s, and multiplies in another time dimension (either 60 s / 1 min or 60 min / 1 h) to get to the requested units of kWh and Joules. To provide a calculator:
J = 60 s/1 min × min × J/s <> W × min × 1 h /60 min = WhSomething which becomes apparent is that both Joules and Watt Hours can be used to describe different scales of electrical energy transfer. It's not unlike measuring volumes of water with both gallons and acre-feet. One watt-hour is one Joule per second, provided for an hour - or 3600 Joules.
From Wikipedia - J represents (approximately):
- The amount of electricity required to run a 1 W device for s.
- The energy required to accelerate a 1 kg mass at m/s2 through a distance of 1 m.
- The kinetic energy of a kg mass traveling at 1.41 m/s.
- The energy required to lift a 101.97 g (3.597 oz) tomato up meters.
- The heat required to raise the temperature of g water from 0 °C (32 °F) to 1 °C (33.8 °F).
- The typical energy released as heat by a person at rest every ms.
- The kinetic energy of a 50 kg human moving at m/s.
- The kinetic energy of a 56 g tennis ball moving at m/s.
- The food energy in about mg table sugar.
02/13/2022 - Happy early spring.
From Wikipedia:
- If Phil sees his shadow and returns to his hole, he has predicted six more weeks of winter-like weather.
- If Phil does not see his shadow, he has predicted an "early spring."
A phenomenon of Seattle life is perpetual overcast. Once I helped a 7 year old kid with a homework assignment - one question was "what color is the sky"? A lifelong resident of the area, she answered "grey". As I explained that "no, the sky is blue, and just covered by one cloud that extends from horizon to horizon" - I started to understand the depression experienced by people who migrate from Florida or California. (This may also be inspiration for The Cloud, as 2 major Cloud Computing providers are based in this area where "the cloud is everywhere" on many days.)
Sunlight diffuses randomly through a heavy cloud layer evenly, so the north and south sides of a buliding receive similarly-low amounts of solar radiation. It gives the odd phenomena where shadows only form as indistinct blobs beneath large objects, like cars. Smaller objects, like groundhogs, may cast effectively no shadow.
- Based on this assumption that Phil would cast no shadow due to a heavy cloud layer, why would this indicate an early spring? Clouds are like blankets, absorbing and reflecting infrared radiation. In fall, they help retain some of the summer heat overnight. In spring, they partially block warm sunlight.
- To complement, if Phil sees his shadow and returns to his den, wouldn't that signal an early spring? The sunlight is going to make for much warmer days and slightly colder nights, giving more energetic solar photons to grow plants more, which animals can eat earlier.
Is it possible that Phil is just misunderstood by our species?
02/08/2022 - RMR calculator.
| Human Gender | Has womb | No womb | Metric | USA! USA! USA! |
|---|---|---|---|---|
| RMR | ||||
| ROReproductive Organ Constant | 444.7593 | 88.362 | ||
| Weight | + 9.247 x | + 13.397 x | kg | lbs |
| Height | + 3.098 x | + 4.799 x | cm | ft |
| Age (years) | - 4.330 x | - 5.677 x |
Formulas from here.
02/04/2022 - Miles per kWH.
Some Car Energy charts I created a while ago, turned into calculators. First, gas mileage calculators:
MPGGal / 100mi
33410.107 WH / Gal
WH / 100mi
WH / mi
Edit: Due to popular demand, here's a cubic inch to liters calculator, and horsepower to kilowatt calculator:
Cu in <> LitersHP <> kW
Second is a fuel cost chart for different miles and MPG combinations:
/ Gal| v Miles v / > MPG > |
|---|
| 2500 |
| 5000 |
| 7500 |
| 10000 |
| 12500 |
| 15000 |
| 17500 |
| 20000 |
| 22500 |
| 25000 |
Finally, a chart showing the amount of energy involved in accelerating to and maintaining each MPH:
Car Weight Lbs <> Car Weight KG| mph |
|---|
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
| 11 |
| 12 |
| 13 |
| 14 |
| 15 |
| 16 |
| 17 |
| 18 |
| 19 |
| 20 |
| 21 |
| 22 |
| 23 |
| 24 |
| 25 |
| 26 |
| 27 |
| 28 |
| 29 |
| 30 |
| 31 |
| 32 |
| 33 |
| 34 |
| 35 |
| 36 |
| 37 |
| 38 |
| 39 |
| 40 |
| 41 |
| 42 |
| 43 |
| 44 |
| 45 |
| 46 |
| 47 |
| 48 |
| 49 |
| 50 |
| 51 |
| 52 |
| 53 |
| 54 |
| 55 |
| 56 |
| 57 |
| 58 |
| 59 |
| 60 |
| 61 |
| 62 |
| 63 |
| 64 |
| 65 |
| 66 |
| 67 |
| 68 |
| 69 |
| 70 |
02/03/2022 - Update to Horsepower and Torque.
Update to my 12/28/2021 post on the difference between Horsepower and Torque. This video helped me to understand the crucial difference:
- Torque is the well-defined concept of force being applied around a circle.
- Horsepower is torque multiplied by RPM.
Why is this significant? This satisfies the time dimension of horsepower by making it the number of times per minute that some torque is applied. The engine is always providing at least a little torque while driving, just not the maximum when at an RPM other than the max torque RPM.
Using the lego example:
| Motor | Torque (Nm) | RPMs | Horsepower |
|---|---|---|---|
| Small | 0.03 | 275 | |
| Large | 0.14 | 146 | |
| Small / Large | 0.14 | 146 |
The video shows the Torque and Horsepower numbers at 4:04, and the Torque and RPMs at 5:50, but the same formula from several sources gives about 25% to 33% too small of a horsepower number here. This is using the conversion constant of 9550, which combines Pi and a few other constants specific for Newton-meters. It's the classic 5252 for foot-pounds. (Pound feet is what children do to get their way.)
Using the sports car vs truck example:
| Motor | Torque (Nm) | RPMs | Horsepower |
|---|---|---|---|
| 3.8L | 633 | 8500 | |
| 13L | 2950 | 1460 | |
| 3.8L / 13L | 0.14 | 146 |
There's a tradeoff here between the amount of power produced foreach revolution, and the max revolutions per minute. This puts both of these into the same range for energy output. (The video mentions the car having a redline of 7000 and the truck with a redline of 2500, so these numbers are a little odd too.)
Going back to torque
Torque is converted into force by the wheels, and likewise is converted from explosive force by the pistons pushing the crankshaft. Internal combustion engines explosively separate two surfaces. More surface area gives more force into the piston, divided across cylinders to even out the power output over time.
Additionally, a wider piston with a shorter rod increases low-end power at the cost of increased friction, which is low at low RPMs. Making each piston a very wide boi with a very short rod will maximize torque, at the cost of max RPMs. This is good for a truck hauling 36 tons, while a car hauling 0.1 tons has the reverse - narrow and long pistons for low friction, to multiply 1/5 as much torque by about 6 times more RPM.
Here's a calculator:
HPRPM
ft-lbs
Nm
02/02/2022 - Composite Key.
//This performs Porta, then Myszkowski, then Running Key. Bugs are multiplicative, so play around with the message and key. It might take some tweaking to get a combo that meets the multiple length and order requirements, and also makes logical sense.
//Key://Message:
//Encrypted:
//Reverted:
02/01/2022 - Inverse Running Key.
//RunningKey cipher uses the first half of the key to encrypt the second half. Not super useful on first glance, but easy enough to make. Then swap the message and key parts, so the first half is encrypted instead of the second half. The average person is going to work to decrypt a message from the beginning, so this adds another layer of encryption over that part, further confounding any decrypter.
//Message://Encrypted:
//Reverted:
//Standard setup, uppercase letters and remove spaces. Message to be encrypted is the first half of the input message, and the encryption key is the last half. And prepare the Out variable. The message length has to be even for this to work correctly.
-
message = message.toUpperCase().replace(/ /g,"");
var msg = message.substring(0, (message.length/2));
var key = message.substring((message.length/2),message.length);
var out = "";
//Loop through the message, converting both the key and message letter into their char code, then drop by 65 to get alphanumeric. Then add these modulus the alphabet, and raise by 65 to get the new char code. Then convert back to an uppercase letter and add to the Out variable.
-
for (messageIndex=0;messageIndex<key.length;messageIndex++) {
-
var keyLetter = key.charCodeAt(messageIndex)-65;
var msgLetter = msg.charCodeAt(messageIndex)-65;
var outLetter = ((keyLetter + msgLetter) % 26)+65;
out += String.fromCharCode(outLetter);
return out;
//Reversion is very similar and starts with literally the same setup.
-
message = message.toUpperCase().replace(/ /g,"");
var msg = message.substring(0, (message.length/2));
var key = message.substring((message.length/2),message.length);
var out = "";
//Likewise, the message loop is nearly identical. The only difference is to subtract the message from the key, and add an alphabet to stay positive, before modulating over the alphabet.
-
for (messageIndex=0;messageIndex<key.length;messageIndex++) {
-
var keyLetter = key.charCodeAt(messageIndex)-65;
var msgLetter = msg.charCodeAt(messageIndex)-65;
var outLetter = ((keyLetter+26-msgLetter) % 26)+65;
out += String.fromCharCode(outLetter);
return out;