Skip to content

Commit 37f94c6

Browse files
refined brain & added IDs to extras sections
1 parent 7b492c3 commit 37f94c6

2 files changed

Lines changed: 55 additions & 46 deletions

File tree

brain.js

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function isolate(word) {
157157
*/
158158
var newWord = "";
159159
S.forEach(word, function (character, index) {
160-
if (character.toLowerCase() != character.toUpperCase()/*|| character=="'"*/) { // if the character is a letter
160+
if (character.toLowerCase() != character.toUpperCase()/*|| character=="'"*/) { // if the character is a letter //// should support contractions
161161
newWord += character;
162162
} else if (character == "{" && word.indexOf("}", index) > -1) {
163163
newWord += word.slice(index, word.indexOf("}", index) + 1);
@@ -180,55 +180,42 @@ function standardize(word) {
180180
qxf{32}xb --> abcdbe
181181
*/
182182
var uniqueLetters = {};
183-
S.forEach(word, function (letter, index, word) {
184-
if (letter.toLowerCase() != letter.toUpperCase()) {
185-
if (uniqueLetters[letter]) {
186-
uniqueLetters[letter].push(index);
187-
} else {
188-
uniqueLetters[letter] = [index];
183+
word.match(/\w|\{\d+\}/g).forEach(function (letter, index) {
184+
if (letter.toLowerCase() != letter.toUpperCase()) { // if it's a letter
185+
if (uniqueLetters[letter]) { // if the letter is already present
186+
uniqueLetters[letter].push(index); // add another index to the unique letter array
187+
} else { // if the letter is unique
188+
uniqueLetters[letter] = [index]; // add the letter's index to uniqueLetters in an array
189189
}
190-
} else if (letter == "{") {
191-
if (uniqueLetters["~" + word.slice(index + 1, word.indexOf("}", index))]) {
192-
uniqueLetters["~" + word.slice(index + 1, word.indexOf("}", index))].push(index);
193-
} else {
194-
uniqueLetters["~" + word.slice(index + 1, word.indexOf("}", index))] = [index];
190+
} else { // if it's a number surrounded by curly braces
191+
if (uniqueLetters["~" + letter.slice(1, -1)]) { // if the character signifier is already present
192+
uniqueLetters["~" + letter.slice(1, -1)].push(index); // add another index to the unique letter array
193+
} else { // if it's a new "letter"
194+
uniqueLetters["~" + letter.slice(1, -1)] = [index]; // add the letter's index to uniqueLetters in an array
195195
}
196-
}/* else {
197-
// do nothing
198-
// (skips the number between any {}s)
199-
} */
196+
}
200197
});
201-
var letters = word.split("");
198+
var letters = word.match(/\w|\{\d+\}/g);
202199
var index = 0;
203-
var shift = 0;
204-
var oldShift;
205-
S.forEach(uniqueLetters, function (numbers) { // This could likely be done with a search-and-replace method. (although going straight to the index is probably faster than a searching method)
206-
numbers.forEach(function (number) {
207-
if (letters[number + shift].toLowerCase() != letters[number + shift].toUpperCase()) {
208-
if (index < 26) {
209-
letters.splice(number + shift, 1, ALPHABET[index]);
200+
Object.keys(uniqueLetters).forEach(function (key) { // This could likely be done with a search-and-replace method. (although going straight to the index is probably faster than a searching method)
201+
uniqueLetters[key].forEach(function (number) { // for every occurence of the unique letter
202+
if (letters[number].toLowerCase() != letters[number].toUpperCase()) { // if the character at the current index is a letter
203+
if (index < 26) { // if there are letters available
204+
letters[number] = ALPHABET[index];
210205
} else { // This should never happen.
211-
oldShift = shift;
212-
shift += ("{" + "{0}").format(index - 26).length; // two braces can't be back-to-back without doing weird stuff
213-
letters.splice(number + oldShift, 1, "{" + (index - 26) + "}");
206+
letters[number] = "{" + (index - 25) + "}";
214207
}
215-
} else if (letters[number + shift] == "{") {
216-
oldShift = shift;
217-
if (index < 26) {
218-
shift -= letters.indexOf("}", number + shift) - (number + shift); // This needs to happen first or else the splice changes things.
219-
letters.splice(number + oldShift, letters.indexOf("}", number + oldShift) - (number + oldShift) + 1, ALPHABET[index]);
220-
} else {
221-
shift += ("{" + "{0}").format(index - 26).length - letters.indexOf("}", number + shift) + (number + shift);
222-
letters.splice(number + oldShift, letters.indexOf("}", number + oldShift) - (number + oldShift) + 1, "{" + (index - 26) + "}");
208+
} else { // if it's a number surrounded by curly braces
209+
if (index < 26) { // if there are letters available
210+
letters[number] = ALPHABET[index]; // convert the notation into a single letter
211+
} else { // if there aren't any unused letters left
212+
letters[number] = "{" + (index - 25) + "}"; // use curly braces notation
223213
}
224214
}
225215
});
226216
index++;
227217
});
228-
word = "";
229-
letters.forEach(function (letter) {
230-
word += letter;
231-
});
218+
word = letters.join("");
232219
return word;
233220
}
234221

@@ -401,6 +388,7 @@ self.addEventListener("message", function (message) {
401388
});
402389
console.info("Total possibilites = " + totalPossibilities);
403390

391+
//* //// primary decoding toggle
404392
function usageCheck(letters) { //// This needs to allow for imperfect matches.
405393
// makes sure a word doesn't conflict with the letters used in previous words
406394
let falseTrue = true;
@@ -476,6 +464,25 @@ self.addEventListener("message", function (message) {
476464
}
477465
}
478466
}
467+
/*/
468+
let encodedMessage = message.data.text;
469+
let shouldContinue = true;
470+
let wordIndex = 0;
471+
while (shouldContinue) {
472+
if (currentIndexList[wordIndex] <= totalIndexList[wordIndex]) { // if there's more possibilities
473+
474+
} else if (wordIndex > 0) {
475+
currentIndexList[wordIndex] = 0;
476+
wordIndex = 0;
477+
currentIndexList[wordIndex]++;
478+
Object.keys(codeKeys).forEach(function (key) {
479+
codeKeys[key] = undefined;
480+
});
481+
} else {
482+
shouldContinue = false;
483+
}
484+
}
485+
//*/
479486
resolve();
480487
}).catch(function (error) {
481488
console.error(error);

extras.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,8 @@
14301430
}
14311431
}
14321432
let appearance = { type: component.type, variation: component.variation };
1433+
/// { ...appearance } shallow copies the object
1434+
/// structuredClone(obj) could copy deeply
14331435
switch (component.type) {
14341436
case "gl":
14351437
if (component.variation) { // if it's a vertical grid line
@@ -2167,7 +2169,7 @@ <h1 class="main-title">
21672169
<section>
21682170
Maybe you've come here in a desperate attempt to find a way of getting around the short-comings of the main decoder or maybe you were just curious after the decoder did its job; regardless, this is primarily just a place for random code-related fun. Feel free to explore.
21692171
</section>
2170-
<h2>
2172+
<h2 id="morseCodeSection">
21712173
Morse Code
21722174
</h2>
21732175
<input type="text" id="morseCodeText">
@@ -2180,14 +2182,14 @@ <h2>
21802182
<button id="randomMorseCode">
21812183
Make a random message in Morse Code
21822184
</button>
2183-
<h2>
2185+
<h2 id="brailleSection">
21842186
Braille
21852187
</h2>
21862188
<textarea id="brailleText" placeholder="Text"></textarea>
21872189
<br>
21882190
<input type="radio" name="brailleDisplay" id="notBrailleShown" checked><label for="notBrailleShown">Normal</label>
21892191
<input type="radio" name="brailleDisplay" id="brailleShown"><label for="brailleShown">Braille</label>
2190-
<h2>
2192+
<h2 id="codeFontSection">
21912193
Code fonts
21922194
</h2>
21932195
<textarea id="substitutedText" placeholder="Text" spellcheck="false"></textarea>
@@ -2795,7 +2797,7 @@ <h2>
27952797
<section>
27962798
The following sections can be used to convert text into various codes. In places where the encrypted section is editable, code can be put in, and decrypted text will be the output. If both inputs are filled, encoding the decrypted text wins out. Double-clicking or touching and holding on an input will erase its text.
27972799
</section>
2798-
<h3>
2800+
<h3 id="emojiCodeSection">
27992801
Password-protected encryption
28002802
</h3>
28012803
<input type="text" id="encryptionKey" placeholder="password">
@@ -2808,7 +2810,7 @@ <h3>
28082810
<button id="encode2">
28092811
Encode
28102812
</button>
2811-
<h3>
2813+
<h3 id="letterCodeSection">
28122814
Letter code
28132815
</h3>
28142816
<textarea id="decrypted1" placeholder="Decoded text"></textarea>
@@ -2817,7 +2819,7 @@ <h3>
28172819
<button id="encode1">
28182820
Encode
28192821
</button>
2820-
<h3>
2822+
<h3 id="sineLanguageSection">
28212823
Sine Language
28222824
</h3>
28232825
<section>
@@ -2849,7 +2851,7 @@ <h3>
28492851
<button id="encode4">
28502852
Encode
28512853
</button>
2852-
<h3>
2854+
<h3 id="symbolCodeSection">
28532855
Symbol code
28542856
</h3>
28552857
<section>

0 commit comments

Comments
 (0)