Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Caesar-cipher/Dyalect/caesar-cipher.dyalect
Normal file
26
Task/Caesar-cipher/Dyalect/caesar-cipher.dyalect
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
func Char.Encrypt(code) {
|
||||
if !this.IsLetter() {
|
||||
return this
|
||||
}
|
||||
var offset = (this.IsUpper() ? 'A' : 'a').Order()
|
||||
return Char((this.Order() + code - offset) % 26 + offset)
|
||||
}
|
||||
|
||||
func String.Encrypt(code) {
|
||||
var xs = []
|
||||
for c in this {
|
||||
xs.Add(c.Encrypt(code))
|
||||
}
|
||||
return String.Concat(values: xs)
|
||||
}
|
||||
|
||||
func String.Decrypt(code) {
|
||||
this.Encrypt(26 - code);
|
||||
}
|
||||
|
||||
var str = "Pack my box with five dozen liquor jugs."
|
||||
print(str)
|
||||
str = str.Encrypt(5)
|
||||
print("Encrypted: \(str)")
|
||||
str = str.Decrypt(5)
|
||||
print("Decrypted: \(str)")
|
||||
Loading…
Add table
Add a link
Reference in a new issue