September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,71 +1,70 @@
|
|||
#define system.
|
||||
#define system'routines.
|
||||
#define system'math.
|
||||
#define extensions.
|
||||
import system'routines.
|
||||
import system'math.
|
||||
import extensions.
|
||||
|
||||
#symbol Letters = "abcdefghijklmnopqrstuvwxyz".
|
||||
#symbol BigLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
|
||||
#symbol TestText = "Pack my box with five dozen liquor jugs.".
|
||||
#symbol Key = 12.
|
||||
const Letters = "abcdefghijklmnopqrstuvwxyz".
|
||||
const BigLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
|
||||
const TestText = "Pack my box with five dozen liquor jugs.".
|
||||
const Key = 12.
|
||||
|
||||
#class Encrypting :: Enumerator
|
||||
class Encrypting :: Enumerator
|
||||
{
|
||||
#field theKey.
|
||||
#field theEnumerator.
|
||||
object theKey.
|
||||
object theEnumerator.
|
||||
|
||||
#constructor new &key:aKey &text:aText
|
||||
constructor new key:aKey text:aText
|
||||
[
|
||||
theKey := aKey.
|
||||
theEnumerator := aText enumerator.
|
||||
]
|
||||
|
||||
#method next => theEnumerator.
|
||||
next => theEnumerator.
|
||||
|
||||
#method reset => theEnumerator.
|
||||
reset => theEnumerator.
|
||||
|
||||
#method get
|
||||
get
|
||||
[
|
||||
#var aChar := theEnumerator get.
|
||||
var aChar := theEnumerator get.
|
||||
|
||||
#var anIndex := Letters indexOf:0:aChar.
|
||||
var anIndex := Letters indexOf:aChar at:0.
|
||||
|
||||
(-1 < anIndex)
|
||||
? [
|
||||
^ Letters @ ((theKey+anIndex) mod:26).
|
||||
]
|
||||
! [
|
||||
anIndex := BigLetters indexOf:0:aChar.
|
||||
(-1 < anIndex)
|
||||
? [
|
||||
^ BigLetters @ ((theKey+anIndex) mod:26).
|
||||
]
|
||||
! [
|
||||
^ aChar.
|
||||
if (-1 < anIndex)
|
||||
[
|
||||
^ Letters[(theKey+anIndex) mod:26]
|
||||
];
|
||||
[
|
||||
anIndex := BigLetters indexOf:aChar at:0.
|
||||
if (-1 < anIndex)
|
||||
[
|
||||
^ BigLetters[(theKey+anIndex) mod:26]
|
||||
];
|
||||
[
|
||||
^ aChar
|
||||
].
|
||||
].
|
||||
]
|
||||
}
|
||||
|
||||
#class(extension)encryptOp
|
||||
extension encryptOp
|
||||
{
|
||||
#method encrypt : aKey
|
||||
= Encrypting new &key:aKey &text:self summarize:(String new).
|
||||
encrypt : aKey
|
||||
= Encrypting new key:aKey text:self; summarize(String new).
|
||||
|
||||
#method decrypt :aKey
|
||||
= Encrypting new &key:(26 - aKey) &text:self summarize:(String new).
|
||||
decrypt :aKey
|
||||
= Encrypting new key(26 - aKey) text:self; summarize(String new).
|
||||
}
|
||||
|
||||
#symbol program =
|
||||
program =
|
||||
[
|
||||
console writeLine:"Original text :" :TestText.
|
||||
console printLine("Original text :",TestText).
|
||||
|
||||
#var anEncryptedText := TestText encrypt:Key.
|
||||
var anEncryptedText := TestText encrypt:Key.
|
||||
|
||||
console writeLine:"Encrypted text:" :anEncryptedText.
|
||||
console printLine("Encrypted text:",anEncryptedText).
|
||||
|
||||
#var aDecryptedText := anEncryptedText decrypt:Key.
|
||||
var aDecryptedText := anEncryptedText decrypt:Key.
|
||||
|
||||
console writeLine:"Decrypted text:" :aDecryptedText.
|
||||
console printLine("Decrypted text:",aDecryptedText).
|
||||
|
||||
console readChar.
|
||||
].
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue