omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / rotational-cipher / .meta / example.om
| 1 | note Exercism-style exercise "rotational-cipher": https://exercism.org/tracks/python/exercises/rotational-cipher |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note rotate writes s into o with every letter shifted key places along the alphabet (keeping its |
| 4 | note case, wrapping z to a) and every other byte unchanged; returns the length. |
| 5 | note Check it with: sh exercise.sh exercises/rotational-cipher |
| 6 | om2 |
| 7 | fn rotate s view uchar * key ulong o edit uchar * to ulong |
| 8 | k = uchar rem key 26 |
| 9 | for i ulong len s |
| 10 | c = get s i |
| 11 | if and ge c 65 le c 90 |
| 12 | c = add 65 rem add sub c 65 k 26 |
| 13 | else |
| 14 | if and ge c 97 le c 122 |
| 15 | c = add 97 rem add sub c 97 k 26 |
| 16 | end |
| 17 | end |
| 18 | put o i c |
| 19 | end |
| 20 | ret len s |
| 21 | end |