September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,73 +1,75 @@
|
|||
import system'routines.
|
||||
import system'math.
|
||||
import extensions.
|
||||
import extensions'text.
|
||||
import system'routines;
|
||||
import system'math;
|
||||
import extensions;
|
||||
import extensions'text;
|
||||
|
||||
const Letters = "abcdefghijklmnopqrstuvwxyz".
|
||||
const BigLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
|
||||
const TestText = "Pack my box with five dozen liquor jugs.".
|
||||
const Key = 12.
|
||||
const string Letters = "abcdefghijklmnopqrstuvwxyz";
|
||||
const string BigLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
const string TestText = "Pack my box with five dozen liquor jugs.";
|
||||
const int Key = 12;
|
||||
|
||||
class Encrypting :: Enumerator
|
||||
class Encrypting : Enumerator
|
||||
{
|
||||
object theKey.
|
||||
object theEnumerator.
|
||||
int theKey;
|
||||
Enumerator theEnumerator;
|
||||
|
||||
constructor key:aKey text:aText
|
||||
[
|
||||
theKey := aKey.
|
||||
theEnumerator := aText enumerator.
|
||||
]
|
||||
constructor(int key, string text)
|
||||
{
|
||||
theKey := key;
|
||||
theEnumerator := text.enumerator();
|
||||
}
|
||||
|
||||
bool next => theEnumerator.
|
||||
bool next() => theEnumerator;
|
||||
|
||||
reset => theEnumerator.
|
||||
reset() => theEnumerator;
|
||||
|
||||
enumerable => theEnumerator.
|
||||
enumerable() => theEnumerator;
|
||||
|
||||
get
|
||||
[
|
||||
var aChar := theEnumerator get.
|
||||
get()
|
||||
{
|
||||
var ch := theEnumerator.get();
|
||||
|
||||
var anIndex := Letters indexOf:aChar at:0.
|
||||
var index := Letters.indexOf(0, ch);
|
||||
|
||||
if (-1 < anIndex)
|
||||
[
|
||||
^ Letters[(theKey+anIndex) mod:26]
|
||||
];
|
||||
[
|
||||
anIndex := BigLetters indexOf:aChar at:0.
|
||||
if (-1 < anIndex)
|
||||
[
|
||||
^ BigLetters[(theKey+anIndex) mod:26]
|
||||
];
|
||||
[
|
||||
^ aChar
|
||||
].
|
||||
].
|
||||
]
|
||||
if (-1 < index)
|
||||
{
|
||||
^ Letters[(theKey+index).mod:26]
|
||||
}
|
||||
else
|
||||
{
|
||||
index := BigLetters.indexOf(0, ch);
|
||||
if (-1 < index)
|
||||
{
|
||||
^ BigLetters[(theKey+index).mod:26]
|
||||
}
|
||||
else
|
||||
{
|
||||
^ ch
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension encryptOp
|
||||
{
|
||||
encrypt : aKey
|
||||
= Encrypting key:aKey text:self; summarize(StringWriter new).
|
||||
encrypt(key)
|
||||
= new Encrypting(key, self).summarize(new StringWriter());
|
||||
|
||||
decrypt :aKey
|
||||
= Encrypting key(26 - aKey) text:self; summarize(StringWriter new).
|
||||
decrypt(key)
|
||||
= new Encrypting(26 - key, self).summarize(new StringWriter());
|
||||
}
|
||||
|
||||
public program =
|
||||
[
|
||||
console printLine("Original text :",TestText).
|
||||
public program()
|
||||
{
|
||||
console.printLine("Original text :",TestText);
|
||||
|
||||
var anEncryptedText := TestText encrypt:Key.
|
||||
var encryptedText := TestText.encrypt:Key;
|
||||
|
||||
console printLine("Encrypted text:",anEncryptedText).
|
||||
console.printLine("Encrypted text:",encryptedText);
|
||||
|
||||
var aDecryptedText := anEncryptedText decrypt:Key.
|
||||
var decryptedText := encryptedText.decrypt:Key;
|
||||
|
||||
console printLine("Decrypted text:",aDecryptedText).
|
||||
console.printLine("Decrypted text:",decryptedText);
|
||||
|
||||
console readChar.
|
||||
].
|
||||
console.readChar()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue