Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
32
Task/Caesar-cipher/Ballerina/caesar-cipher.ballerina
Normal file
32
Task/Caesar-cipher/Ballerina/caesar-cipher.ballerina
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import ballerina/io;
|
||||
|
||||
function encrypt(string s, int key) returns string {
|
||||
final int offset = key % 26;
|
||||
if offset == 0 { return s; }
|
||||
int d;
|
||||
int[] chars = [];
|
||||
foreach int c in s.toCodePointInts() {
|
||||
if c >= 64 && c <= 90 {
|
||||
d = c + offset;
|
||||
if d > 90 { d -= 26; }
|
||||
} else if c >= 97 && c <= 122 {
|
||||
d = c + offset;
|
||||
if d > 122 { d -= 26; }
|
||||
} else {
|
||||
d = c;
|
||||
}
|
||||
chars.push(d);
|
||||
}
|
||||
return checkpanic string:fromCodePointInts(chars);
|
||||
}
|
||||
|
||||
function decrypt(string s, int key) returns string {
|
||||
return encrypt(s, 26 - key);
|
||||
}
|
||||
|
||||
public function main() {
|
||||
string encoded = encrypt("Bright vixens jump; dozy fowl quack.", 8);
|
||||
io:println(encoded);
|
||||
string decoded = decrypt(encoded, 8);
|
||||
io:println(decoded);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue