Page MenuHomeDevCentral

D2246.diff
No OneTemporary

D2246.diff

diff --git a/geocaching/_documents.xml b/geocaching/_documents.xml
--- a/geocaching/_documents.xml
+++ b/geocaching/_documents.xml
@@ -9,4 +9,9 @@
<title>Numeric operations from strings</title>
<description>Gets numbers from strings content.</description>
</document>
+ <document>
+ <article>caesar</article>
+ <title>Caesar cipher</title>
+ <description>Shift message letters.</description>
+ </document>
</documents>
diff --git a/geocaching/caesar.html b/geocaching/caesar.html
new file mode 100644
--- /dev/null
+++ b/geocaching/caesar.html
@@ -0,0 +1,44 @@
+<h2>Caesar cipher</h2>
+<form>
+<div class="row collapse" style="margin-bottom: 1em;">
+ <h3>Source text</h3>
+ <textarea rows="4" name="text" id="text" placeholder="Lorem ipsum dolor sit amet nunc abuntur - Write here the text to rewrite."></textarea>
+
+ <h3>Permutations</h3>
+ <div id="permutations"><em>Write some text above to compute permutations.</em></div>
+</div>
+</form>
+<script>
+function shiftLetter(c, k) {
+ const baseValue = c.charCodeAt(0) - 64
+
+ if (baseValue < 0 || baseValue > 26) {
+ return c
+ }
+
+ shiftedValue = (baseValue + 26 - k) % 26
+
+ if (shiftedValue === 0) {
+ shiftedValue = 26 // Z and not @
+ }
+
+ return String.fromCharCode(64 + shiftedValue)
+}
+
+function permute(sourceText, targetElement) {
+ targetElement.empty()
+
+ for (let k = 1 ; k < 26 ; k++) {
+ permutedText = sourceText
+ .split('')
+ .map(c => shiftLetter(c, k))
+ .join('')
+
+ targetElement.append("<p>" + permutedText + "</p>")
+ }
+}
+
+$('#text').bind('input propertychange', function() {
+ permute($(this).val().toUpperCase(), $("#permutations"))
+})
+</script>
diff --git a/geocaching/index.php b/geocaching/index.php
--- a/geocaching/index.php
+++ b/geocaching/index.php
@@ -1,4 +1,5 @@
<h2>Geocaching</h2>
<ul>
<li><a href="/geocaching/string2number">String to number</a></li>
+ <li><a href="/geocaching/caesar">Caesar cipher</a></li>
</ul>
diff --git a/themes/RalfFallsIntoFoundation/footer.php b/themes/RalfFallsIntoFoundation/footer.php
--- a/themes/RalfFallsIntoFoundation/footer.php
+++ b/themes/RalfFallsIntoFoundation/footer.php
@@ -27,6 +27,7 @@
<dd><a href="/microblogging/twitterpoints">Twitter Points</a></dd>
<dt>Geocaching</dt>
+ <dd><a href="/geocaching/caesar">Caesar cipher</a></dd>
<dd><a href="/geocaching/string2number">String to number</a></dd>
</dl>
</div>

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 17, 05:24 (21 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2248711
Default Alt Text
D2246.diff (2 KB)

Event Timeline