// ================= Word Breakdown & Cipher Chart ================== function getSum(total, num) { // used to .reduce() array, adds all values return total + num; } function gemCalcModeLabel(curCipher) { if (optGemMultCharPos && curCipher.LetterCount > 0) return ' - x1 ... x'+curCipher.LetterCount else if (optGemMultCharPosReverse && curCipher.LetterCount > 0) return ' - x'+curCipher.LetterCount+' ... x1' return "" } function updateWordBreakdown(impName = breakCipher, impBool = false, chartUpd = true) { // false - preview temporary (hover), true - lock breakdown to a specific cipher var x, curCipher, curCiphCol, cSpot var o, oo, acw, acl updateEnabledCipherCount() $("#BreakTableContainer").removeClass("hideValue") // unhide breakdown $("#BreakdownDetails").attr("style", "") // reset padding (gematria card) if (impBool == true) breakCipher = impName // lock to a specific cipher if (!optShowCipherChart) $("#ChartSpot").attr("style", "border: none;"); // reset gradient for cipher chart if (enabledCiphCount == 0 || breakCipher == "" && impName == "") { document.getElementById("BreakdownSpot").innerHTML = "" document.getElementById("ChartSpot").innerHTML = "" $("#ChartSpot").attr("style", "border: none;"); // reset gradient for cipher chart return; } for (x = 0; x < cipherList.length; x++) { if (cipherList[x].cipherName == impName) { cSpot = x if (chartUpd) updateCipherChart(cipherList[x]) break } } curCipher = cipherList[cSpot] curCiphCol = (optColoredCiphers) ? 'color: hsl('+curCipher.H+' '+curCipher.S+'% '+curCipher.L+'% / 1)' : '' curGradCol = (optColoredCiphers) ? 'hsl('+curCipher.H+' '+curCipher.S+'% '+curCipher.L+'% / 0.2)' : 'hsl(0 0% 0% / 0.1)' var leftToRightBreak = true // if Hebrew Aleph is assigned in current cipher if (curCipher.cArr.indexOf(1488) > -1) { curCipher.calcBreakdown(sVal().replace(/[\u0591-\u05BD\u05BF-\u05C7]/g,"")) // remove Hebrew vowels, exclude dash } // if Arabic Alef is assigned in current cipher if (curCipher.cArr.indexOf(1575) > -1) { curCipher.calcBreakdown(sVal().replace(/[\u0600-\u061F\u0640\u064B-\u066D\u06D4\u06D6-\u06ED\u06F0-\u06F9]/g,"")) // remove Arabic marks and non letter characters } // use right to left writing (Hebrew, Arabic) if (curCipher.cArr.indexOf(1488) > -1 || curCipher.cArr.indexOf(1575) > -1) { curCipher.cp.reverse(); curCipher.cv.reverse(); curCipher.sumArr.reverse() // right-to-left direction if (curCipher.WordCount > 1) { curCipher.cp.push(curCipher.cp.shift()) // remove first element and add to the end of array (space, used for word sum) curCipher.cv.push(curCipher.cv.shift()) } leftToRightBreak = false } else { // left to right, use regular word breakdown curCipher.calcBreakdown(sVal()) // calculate breakdown for current phrase } if (curCipher.sumArr.length > 0) { var oStart = ''; var o =''; var RTLclass = ''; if (!leftToRightBreak) RTLclass = 'BreakRTL' // use different container padding for right to left direction if (optLetterWordCount == true) { if (curCipher.LetterCount > 1 || curCipher.LetterCount == 0) {acl = " letters, "} else {acl = " letter, "} if (curCipher.WordCount > 1) {acw = " words"} else {acw = " word"} oStart += '
' + curCipher.LetterCount + acl + curCipher.WordCount + acw + '
' } if (optCompactBreakdown == true) { var simplePhr = "" if (optAllowPhraseComments) { simplePhr = sValNoComments() // exclude text inside [...] } else { simplePhr = sVal() // display full phrase } oStart += '
' oStart += '' + simplePhr + ' = ' + curCipher.sumArr.reduce(getSum) + ' ' // add all values in array oStart += ' (' + curCipher.cipherName + gemCalcModeLabel(curCipher) + ')' } if (optWordBreakdown == true && curCipher.cp.length <= chLimit ) { // character limit, calculated even if out of screen bounds var tdCount = 0; var wCount = 0; o += '
' o += '' if (leftToRightBreak) { // left to right for (x = 0; x < curCipher.cp.length; x++) { if (curCipher.cp[x] !== " ") { if (String(curCipher.cp[x]).substring(0, 3) == "num") { o += '' } else { o += '' } } else { o += '' wCount++ } tdCount++ } o += '' o += '' tdCount++ for (z = 0; z < x; z++) { if (curCipher.cv[z] !== " ") { o += '' } } } else { // right to left (Hebrew, Arabic) o += '' var curBreakWord = '' // current word, added to main 'o' string for (x = 0; x < curCipher.cp.length; x++) { if (curCipher.cp[x] !== " ") { if (String(curCipher.cp[x]).substring(0, 3) == "num") { curBreakWord += '' } else { curBreakWord += '' } } else { curBreakWord = '' + curBreakWord // prepend word sum (displayed on the left) o += curBreakWord curBreakWord = '' wCount++ } tdCount++ } if (curCipher.WordCount == 1) o += curBreakWord // single word o += '' tdCount++ for (z = 0; z < x; z++) { if (curCipher.cv[z] !== " ") { o += '' } } } ciphEndClass = (leftToRightBreak) ? "CipherEnd" : "CipherEndRTL" if (optCompactBreakdown == true) o += '
' + curCipher.cp[x].substring(3, curCipher.cp[x].length) + '' + String.fromCharCode(curCipher.cp[x]) + '' + curCipher.sumArr[wCount] + '' + curCipher.sumArr.reduce(getSum) + '
' + curCipher.cv[z] + '' + curCipher.sumArr.reduce(getSum) + '' + curCipher.cp[x].substring(3, curCipher.cp[x].length) + '' + String.fromCharCode(curCipher.cp[x]) + '' + curCipher.sumArr[wCount] + '
' + curCipher.cv[z] + '
' + curCipher.cipherName + gemCalcModeLabel(curCipher) + '
' else o += '' o = oStart + o // prepend phrase, word/letter count } else if (optWordBreakdown == true && curCipher.cp.length > chLimit) { // breakdown for long phrases var wrdCount = 0; var z = 0; var breakArr = buildLongBreakdown(curCipher) // index of word in phraseBox, used to mark table end var curBreakRow = '' // current row, added to main 'o' string if (leftToRightBreak) { // left to right curBreakRow = '' for (x = 0; x < curCipher.cp.length; x++) { if (curCipher.cp[x] !== " ") { if (String(curCipher.cp[x]).substring(0, 3) == "num") { curBreakRow += '' } else { curBreakRow += '' } } else { // show character values and word sum if space curBreakRow += '' if (breakArr.indexOf(wrdCount) > -1 || wrdCount == curCipher.WordCount-1) { // include values for last word curBreakRow += '' for (z; z < x; z++) { if (curCipher.cv[z] !== " ") { curBreakRow += '' } } curBreakRow += '
' + curCipher.cp[x].substring(3, curCipher.cp[x].length) + '' + String.fromCharCode(curCipher.cp[x]) + '' + curCipher.sumArr[wrdCount] + '
' + curCipher.cv[z] + '
' if (wrdCount !== curCipher.WordCount-1) curBreakRow += '' } wrdCount++ } } if (curCipher.cp.indexOf(" ") == -1) { // show character values if one long word (has no " ") curBreakRow += '' for (z; z < x; z++) { if (curCipher.cv[z] !== " ") { curBreakRow += '' } } curBreakRow += '
' + curCipher.cv[z] + '
' } o = '
' + curBreakRow } else { // right to left (Hebrew, Arabic) curBreakRow = '' if (curCipher.WordCount > 1) curBreakRow += '' for (x = 0; x < curCipher.cp.length; x++) { if (curCipher.cp[x] !== " ") { if (String(curCipher.cp[x]).substring(0, 3) == "num") { curBreakRow += '' } else { curBreakRow += '' } } else { // show character values and word sum if space or last character if (breakArr.indexOf(wrdCount) > -1 || wrdCount == curCipher.WordCount-1) { // include values for last word curBreakRow += '' for (z; z < x; z++) { if (curCipher.cv[z] !== " ") { curBreakRow += '' } } curBreakRow += '
' + curCipher.sumArr[wrdCount] + '' + curCipher.cp[x].substring(3, curCipher.cp[x].length) + '' + String.fromCharCode(curCipher.cp[x]) + '
' + curCipher.cv[z] + '
' o = curBreakRow + o // prepend current row to main table if (wrdCount !== curCipher.WordCount-1) curBreakRow = '' } wrdCount++ if (wrdCount !== curCipher.WordCount) curBreakRow += '' } } if (curCipher.cp.indexOf(" ") == -1) { // show character values if one long word (has no " ") curBreakRow += '' for (z; z < x; z++) { if (curCipher.cv[z] !== " ") { curBreakRow += '' } } curBreakRow += '
' + curCipher.sumArr[wrdCount] + '
' + curCipher.cv[z] + '
' o = curBreakRow + o // prepend current row to main table } o = '
' + o // prepend opening div, include padding } o = oStart + o // prepend phrase, word/letter count if (optCompactBreakdown == true) { o += '
' + curCipher.sumArr.reduce(getSum) + ' ' o += '' + curCipher.cipherName + gemCalcModeLabel(curCipher) + '
' } else { o += '
' } } } else { o = "" } document.getElementById("BreakdownSpot").innerHTML = o if (curCipher.sumArr.length > 0 && optCompactBreakdown == false) { // include plain phrase inside breakdown chart var simplePhr = "" if (optAllowPhraseComments) { simplePhr = sValNoComments() // exclude text inside [...] } else { simplePhr = sVal() // display full phrase } var chartClass = 'SimpleBreakChart' if (curCipher.cp.length > chLimit) chartClass = 'SimpleBreakChartLong' o = '' o += '
' + simplePhr + ' = ' + curCipher.sumArr.reduce(getSum) + ' ' // add all values in array o += '(' + curCipher.cipherName + gemCalcModeLabel(curCipher) + ')
' $('#BreakTableContainer').prepend(o) // insert in the beginning of the table } oo = 'background: var(--body-bg-accent);' if (optGradientCharts) { oo = 'background: '+bgCol+' -webkit-linear-gradient(0deg,'+curGradCol+', rgba(0,0,0,0.0));' oo += 'background: '+bgCol+' -o-linear-gradient(0deg,'+curGradCol+', rgba(0,0,0,0.0));' oo += 'background: '+bgCol+' -moz-linear-gradient(0deg,'+curGradCol+', rgba(0,0,0,0.0));' oo += 'background: '+bgCol+' linear-gradient(0deg,'+curGradCol+', rgba(0,0,0,0.0));' } $("#BreakTableContainer").attr("style", oo); } function buildLongBreakdown(curCipher) { var i; var newLine = true; words = 0; n = ""; var breakArr = []; var widthCount = 0; for (i = 0; i < curCipher.cv.length; i++) { if (curCipher.cv[i] !== " ") { if (n == "") {n = i} if (curCipher.cv[i] > 99) { widthCount += 1.5 } else { widthCount++ } if (widthCount > maxRowWidth && newLine == false) { breakArr.push(words - 1) widthCount = 0 i = n - 1 newLine = true } } else { widthCount += 2 words++ n = "" newLine = false } } return breakArr } function updateCipherChart(curCipher) { if (optShowCipherChart == false) { document.getElementById("ChartSpot").innerHTML = "" return } curCiphCol = (optColoredCiphers) ? 'color: hsl('+curCipher.H+' '+curCipher.S+'% '+curCipher.L+'% / 1)' : '' curCiphFaintCol = (optColoredCiphers) ? 'color: hsl('+curCipher.H+' '+curCipher.S+'% '+curCipher.L+'% / 0.25)' : '' curGradCol = (optColoredCiphers) ? 'hsl('+curCipher.H+' '+curCipher.S+'% '+curCipher.L+'% / 0.2)' : 'hsl(0 0% 0% / 0.1)' var o = 'background: var(--body-bg-accent);' if (optGradientCharts) { o = 'background: '+bgCol+' -webkit-linear-gradient(0deg,'+curGradCol+', rgba(0,0,0,0.0));' o += 'background: '+bgCol+' -o-linear-gradient(0deg,'+curGradCol+', rgba(0,0,0,0.0));' o += 'background: '+bgCol+' -moz-linear-gradient(0deg,'+curGradCol+', rgba(0,0,0,0.0));' o += 'background: '+bgCol+' linear-gradient(0deg,'+curGradCol+', rgba(0,0,0,0.0));' } o += 'min-height: 166px;' // avoid layout shift when Agrippa ciphers are active o += 'margin-top: 1em;' o += 'margin-bottom: 0.5em;' o += 'padding: 0.8em;' $("#ChartSpot").attr("style", o); o = '' o += '' o += '' o += '' // Space o += '' o += '' // Backspace o += '' var halfL = curCipher.cArr.length / 2 for (var x = 0; x < curCipher.cArr.length; x++) { if (x - halfL == 0 || x - halfL == 0.5) { o += '' for (var y = 0; y < x; y++) { // 2nd row (values) o += '' } o += '' } o += (showCapsCipherChart && !curCipher.caseSensitive) ? '' : '' } if (curCipher.cArr.length % 2 == 1) { o += '' } // empty character cell to make even rows o += '' for (y; y < x; y++) { o += '' // 4th row (values) } if (curCipher.cArr.length % 2 == 1) { o += '' } // empty value cell to make even rows o += '
-' o += '' + curCipher.cipherName + '' o += '←
' + curCipher.vArr[y] + '
' + String.fromCodePoint(curCipher.cArr[x]).toUpperCase() + '' + String.fromCodePoint(curCipher.cArr[x]) + '
' + curCipher.vArr[y] + '
' document.getElementById("ChartSpot").innerHTML = o } function updateCipherChartGemCard(impName = breakCipher) { if (optShowCipherChart == false) { document.getElementById("ChartSpot").innerHTML = "" return } var cSpot for (x = 0; x < cipherList.length; x++) { if (cipherList[x].cipherName == impName) { cSpot = x; break; } } curCipher = cipherList[cSpot] curCiphCol = (optColoredCiphers) ? 'color: hsl('+curCipher.H+' '+curCipher.S+'% '+curCipher.L+'% / 1)' : '' curGradCol = (optColoredCiphers) ? 'hsl('+curCipher.H+' '+curCipher.S+'% '+curCipher.L+'% / 0.2)' : 'hsl(0 0% 0% / 0.1)' // gradient table background based on cipher color o = '' if (optGradientCharts) { o = '
' } o += '' o += '' var halfL = curCipher.cArr.length / 2 for (var x = 0; x < curCipher.cArr.length; x++) { if (x - halfL == 0 || x - halfL == 0.5) { o += '' for (var y = 0; y < x; y++) { // 2nd row (values) o += '' } o += '' } o += '' } if (curCipher.cArr.length % 2 == 1) { o += '' } // empty character cell to make even rows o += '' for (y; y < x; y++) { o += '' // 4th row (values) } if (curCipher.cArr.length % 2 == 1) { o += '' } // empty value cell to make even rows o += '
' o += '' + curCipher.cipherName + '' o += '
' + curCipher.vArr[y] + '
' + String.fromCodePoint(curCipher.cArr[x]) + '
' + curCipher.vArr[y] + '
' document.getElementById("ChartSpot").innerHTML = o $("#ChartTable").addClass("borderCipherTable") // cipher chart with borders o = 'border: none;' // clear div gradient background, remove border o += 'margin-top: 1em;' o += 'margin-bottom: 0.5em;' o += 'padding: 0.4em;' $("#ChartSpot").attr("style", o) }