Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,59 +1,74 @@
#define std'dictionary'*.
#define std'basic'*.
#define std'patterns'*.
#define std'routines'strings'*.
#define system.
#define system'routines.
#define extensions.
#define extensions'math.
#define math'* = std'math'*.
// --- subjects ---
#subject cipher_key.
// --- Constants ---
#symbol Letters = "abcdefghijklmnopqrstuvwxyz".
#symbol BigLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
#symbol TestText = "Pack my box with five dozen liquor jugs.".
#symbol Key = 12.
#symbol EEncrypt : aKey =
// --- Encrypt / Decript ---
#class Encrypting
{
eval : aChar
#field theKey.
#field theExtendee.
#constructor new : aKey &extending:anObject
[
#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.
].
].
theKey := aKey.
theExtendee := anObject.
]
}.
#symbol Encrypted &literal:aLiteral &cipher_key:aKey
= __group(EEncrypt::aKey, Summing::String) start:Scan::aLiteral.
#method eval : aChar
[
#var anIndex := Letters indexOf &index:0 &char:aChar.
#symbol Decrypted &literal:aLiteral &cipher_key:aKey
= __group(EEncrypt::(26 - aKey), Summing::String) start:Scan::aLiteral.
(-1 < anIndex)
? [
theExtendee eval:(Letters @ (modulus:(theKey+anIndex):26))
]
! [
anIndex := BigLetters indexOf &index:0 &char:aChar.
(-1 < anIndex)
? [
theExtendee eval:(BigLetters @ (modulus:(theKey+anIndex):26))
]
! [
theExtendee eval:aChar.
].
].
]
#symbol Program =
#method => theExtendee.
}
// --- Functions ---
#symbol encrypt = (:aText:aKey)
[ Encrypting new:aKey &extending:(Summing new:(String new)) foreach:aText literal ].
#symbol decrypt = (:aText:aKey)
[ Encrypting new:(26 - aKey) &extending:(Summing new:(String new)) foreach:aText literal ].
// --- Program ---
#symbol program =
[
#var anS := TestText.
'program'output << "Original text :" << anS << "%n".
consoleEx writeLine:"Original text :" :anS.
anS := Encrypted &&literal:anS &cipher_key:Key.
anS := encrypt:anS:Key.
'program'output << "Encrypted text:" << anS << "%n".
consoleEx writeLine:"Encrypted text:" :anS.
anS := Decrypted &&literal:anS &cipher_key:Key.
anS := decrypt:anS:Key.
'program'output << "Decrypted text:" << anS << "%n".
consoleEx writeLine:"Decrypted text:" :anS.
'program'input get.
consoleEx readChar.
].