example: add caesar cipher example from rosetta code
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 10 Jun 2015 19:16:59 +0000 (15:16 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 10 Jun 2015 19:16:59 +0000 (15:16 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

examples/rosettacode/caesar_cipher.nit [new file with mode: 0644]
tests/sav/caesar_cipher.res [new file with mode: 0644]

diff --git a/examples/rosettacode/caesar_cipher.nit b/examples/rosettacode/caesar_cipher.nit
new file mode 100644 (file)
index 0000000..e6d6272
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/env nit
+#
+# This file is part of NIT ( http://www.nitlanguage.org ).
+# This program is public domain
+
+# Task: Ceasar cipher
+# SEE: <http://rosettacode.org/wiki/Caesar_cipher>
+module caesar_cipher
+
+import crypto
+
+var key = 31
+var msg = "Batman's hood is called a \"cowl\" (old meaning)."
+var cipher = msg.rot(key)
+
+print "Caesar cypher key: {key}"
+print "plain text: {msg}"
+print "cyphered: {cipher}"
+print "uncyphered: {cipher.rot(-key)}"
diff --git a/tests/sav/caesar_cipher.res b/tests/sav/caesar_cipher.res
new file mode 100644 (file)
index 0000000..b8e2662
--- /dev/null
@@ -0,0 +1,4 @@
+Caesar cypher key: 31
+plain text: Batman's hood is called a "cowl" (old meaning).
+cyphered: Gfyrfs'x mtti nx hfqqji f "htbq" (tqi rjfsnsl).
+uncyphered: Batman's hood is called a "cowl" (old meaning).