interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / atbash-cipher / .meta / example.om

55 lines · 1125 bytes Raw Blame History
1note Exercism-style exercise "atbash-cipher": https://exercism.org/tracks/python/exercises/atbash-cipher
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note encode writes the Atbash cipher of s into o (a to z, b to y, ...; letters lower case, digits
4note kept, everything else dropped) in groups of 5 separated by one space; decode writes the plain
5note text of s (spaces dropped). Both return the number of bytes written.
6note Check it with: sh exercise.sh exercises/atbash-cipher
7om2
8fn encode s view uchar * o edit uchar * to ulong
9p = ulong 0
10k = ulong 0
11for i ulong len s
12c = get s i
13if and ge c 65 le c 90
14c = add c 32
15end
16keep = false
17if and ge c 97 le c 122
18c = sub 219 c
19keep = true
20else
21if and ge c 48 le c 57
22keep = true
23end
24end
25if keep
26if and gt k 0 eq rem k 5 0
27put o p 32
28p = add p 1
29end
30put o p c
31p = add p 1
32k = add k 1
33end
34end
35ret p
36end
37fn decode s view uchar * o edit uchar * to ulong
38p = ulong 0
39for i ulong len s
40c = get s i
41if and ge c 65 le c 90
42c = add c 32
43end
44if and ge c 97 le c 122
45put o p sub 219 c
46p = add p 1
47else
48if and ge c 48 le c 57
49put o p c
50p = add p 1
51end
52end
53end
54ret p
55end