Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -1,74 +1,71 @@
#define system.
#define system'routines.
#define extensions.
#define system'math.
// --- Constants ---
#define extensions.
#symbol Letters = "abcdefghijklmnopqrstuvwxyz".
#symbol BigLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
#symbol TestText = "Pack my box with five dozen liquor jugs.".
#symbol Key = 12.
// --- Encrypt / Decript ---
#class Encrypting
#class Encrypting :: Enumerator
{
#field theKey.
#field theExtendee.
#field theEnumerator.
#constructor new : aKey &extending:anObject
#constructor new &key:aKey &text:aText
[
theKey := aKey.
theExtendee := anObject.
theEnumerator := aText enumerator.
]
#method eval : aChar
#method next => theEnumerator.
#method reset => theEnumerator.
#method get
[
#var anIndex := Letters indexOf &index:0 &char:aChar.
#var aChar := theEnumerator get.
#var anIndex := Letters indexOf:0:aChar.
(-1 < anIndex)
? [
theExtendee eval:(Letters @ ((theKey+anIndex) int mod:26))
^ Letters @ ((theKey+anIndex) mod:26).
]
! [
anIndex := BigLetters indexOf &index:0 &char:aChar.
anIndex := BigLetters indexOf:0:aChar.
(-1 < anIndex)
? [
theExtendee eval:(BigLetters @ ((theKey+anIndex) int mod:26))
^ BigLetters @ ((theKey+anIndex) mod:26).
]
! [
theExtendee eval:aChar.
^ aChar.
].
].
]
#method => theExtendee.
}
// --- Functions ---
#class(extension)encryptOp
{
#method encrypt : aKey
= Encrypting new &key:aKey &text:self summarize:(String new).
#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 ---
#method decrypt :aKey
= Encrypting new &key:(26 - aKey) &text:self summarize:(String new).
}
#symbol program =
[
#var anS := TestText.
console writeLine:"Original text :" :TestText.
consoleEx writeLine:"Original text :" :anS.
#var anEncryptedText := TestText encrypt:Key.
anS := encrypt:anS:Key.
console writeLine:"Encrypted text:" :anEncryptedText.
consoleEx writeLine:"Encrypted text:" :anS.
#var aDecryptedText := anEncryptedText decrypt:Key.
anS := decrypt:anS:Key.
console writeLine:"Decrypted text:" :aDecryptedText.
consoleEx writeLine:"Decrypted text:" :anS.
consoleEx readChar.
console readChar.
].