This commit is contained in:
Ingy döt Net 2013-04-10 16:57:12 -07:00
parent 518da4a923
commit 764da6cbbb
6144 changed files with 83610 additions and 11 deletions

View file

@ -0,0 +1,59 @@
#define std'dictionary'*.
#define std'basic'*.
#define std'patterns'*.
#define std'routines'strings'*.
#define math'* = std'math'*.
// --- subjects ---
#subject cipher_key.
#symbol Letters = "abcdefghijklmnopqrstuvwxyz".
#symbol BigLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
#symbol TestText = "Pack my box with five dozen liquor jugs.".
#symbol Key = 12.
#symbol EEncrypt : aKey =
{
eval : aChar
[
#var anIndex := Letters~eliteralop first_occ'find:aChar.
#if (-1) ifless:anIndex
[
$next eval:(Letters @ (aKey + anIndex)~math'eops math'modulus:26).
]
| [
anIndex := BigLetters~eliteralop first_occ'find:aChar.
#if (-1) ifless:anIndex
[
$next eval:(BigLetters @ (aKey + anIndex)~math'eops math'modulus:26).
]
| [
$next eval:aChar.
].
].
]
}.
#symbol Encrypted &literal:aLiteral &cipher_key:aKey
= __group(EEncrypt::aKey, Summing::String) start:Scan::aLiteral.
#symbol Decrypted &literal:aLiteral &cipher_key:aKey
= __group(EEncrypt::(26 - aKey), Summing::String) start:Scan::aLiteral.
#symbol Program =
[
#var anS := TestText.
'program'output << "Original text :" << anS << "%n".
anS := Encrypted &&literal:anS &cipher_key:Key.
'program'output << "Encrypted text:" << anS << "%n".
anS := Decrypted &&literal:anS &cipher_key:Key.
'program'output << "Decrypted text:" << anS << "%n".
'program'input get.
].