Skip to content

Instantly share code, notes, and snippets.

@pietroppeter
Created October 22, 2020 19:51
Show Gist options
  • Save pietroppeter/340a7a96ec5e189ff2ffcb3836f387ee to your computer and use it in GitHub Desktop.
Save pietroppeter/340a7a96ec5e189ff2ffcb3836f387ee to your computer and use it in GitHub Desktop.
nimib preview
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<title>world.nim</title>
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel='stylesheet' href='https://unpkg.com/normalize.css/' type='text/css'>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/light.min.css">
</head>
<body>
<h2>Secret talk with a computer</h2>
<p>in this document I will show you how to talk with the computer like a <a href="https://mango.pdf.zone/">real hacker</a>!</p>
<h3>A secret message</h3>
<p>Inside this document is hidden a super secret message, the only way to see it
(other than checking the source)
is forcing the computer to spit out and confess:</p>
<pre><code class="nim">echo secret</code></pre>
<pre>[104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]</pre>
<p>what does the computer want to say? It is almost impossible to say,
it looks like a completely random integer sequence
(yeah, <a href="https://oeis.org/search?q=104%2C+101%2C+108%2C+108%2C+111%2C+44%2C+32%2C+119%2C+111%2C+114%2C+108%2C+100&language=english&go=Search">well</a>).</p>
<h3>A cryptoanalytic weapon</h3>
<p>I actually happen to have one of the most powerful crypto-cracking device, a nim <code>func</code>,
that will allow us to decipher this enigmatic message. Here it is:</p>
<pre><code class="nim">func decode(secret: openArray[int]): string =
## classified by NSA as <a href="https://www.nsa.gov/Portals/70/documents/news-features/declassified-documents/cryptologic-histories/EC-121.pdf">TOP SECRET</a>
for c in secret:
result.add char(c)</code></pre>
<h3>The great revelation</h3>
<p>Although the algorithm is too complicated for me to understand,
I can just apply it to my secret message and
finally decrypt what the computer wants to tell me:</p>
<pre><code class="nim">let msg = decode secret
echo msg</code></pre>
<pre>hello, world</pre>
<p><em>Hey</em>, there must be a bug somewhere, the message (<code>hello, world</code>) is not even addressed to me!</p>
</body>
</html>
import strformat, strutils
include nimib / prelude
nbText: """
## Secret talk with a computer
in this document I will show you how to talk with the computer like a [real hacker](https://mango.pdf.zone/)!
### A secret message
Inside this document is hidden a super secret message, the only way to see it
(other than checking the source)
is forcing the computer to spit out and confess:
"""
let secret = [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]
nbCode:
echo secret
nbText: fmt"""
what does the computer want to say? It is almost impossible to say,
it looks like a completely random integer sequence
(yeah, [well](https://oeis.org/search?q={secret.join("%2C+")}&language=english&go=Search)).
### A cryptoanalytic weapon
I actually happen to have one of the most powerful crypto-cracking device, a nim `func`,
that will allow us to decipher this enigmatic message. Here it is:"""
nbCode:
func decode(secret: openArray[int]): string =
## classified by NSA as <a href="https://www.nsa.gov/Portals/70/documents/news-features/declassified-documents/cryptologic-histories/EC-121.pdf">TOP SECRET</a>
# so secret that they do not want me to tell you and they will remove this message
for c in secret:
result.add char(c)
nbText: """
### The great revelation
Although the algorithm is too complicated for me to understand,
I can just apply it to my secret message and
finally decrypt what the computer wants to tell me:"""
nbCode:
let msg = decode secret
echo msg
nbText:
fmt"_Hey_, there must be a bug somewhere, the message (`{msg}`) is not even addressed to me!"
show nbDoc
@pietroppeter
Copy link
Author

pietroppeter commented Oct 22, 2020

this is a screenshot of the above html

hello_nimib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment