Skip to content

Commit e2ecf90

Browse files
authored
Overhauled Atbash (#141)
1 parent 8913a01 commit e2ecf90

28 files changed

+186
-197
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ problems/%:
1717
clean: ## Delete all log files produced by the test script for failing tests.
1818
shopt -s globstar
1919
rm -f problems/**/*.exe problems/**/*.log
20+
21+
executables:
22+
shopt -s extglob globstar
23+
chmod +x problems/**/*.+(bash|dart|jl|js|kt|kts|php|py|rb|sh|ts|zsh)

problems/atbash/README.md

+24-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
Atbash is a simple substitution cipher originally for the Hebrew alphabet, but possible with any known alphabet.
2-
```
3-
Original: abcdefghijklmnopqrstuvwxyz
4-
Substitute: ZYXWVUTSRQPONMLKJIHGFEDCBA
5-
```
1+
# Atbash
62

7-
So you would substitute "a" in your input text with "Z" in your output text, "b" with "Y", "c" with "X" and so forth.
3+
[Atbash] is a simple substitution cipher originally for the Hebrew alphabet, but
4+
possible with any known alphabet.
85

9-
A few English words also 'Atbash' into other English words: "irk"="rip", "low"="old", "hob"="sly", "hold"="slow", "holy"="slob", "horn"="slim", "glow"="told", "grog"="tilt" and "zoo"="all". Some other English words Atbash into their own reverses, e.g., "wizard" = "draziw."
6+
Original: `abcdefghijklmnopqrstuvwxyz`
7+
Substitute: `zyxwvutsrqponmlkjihgfedcba`
108

11-
(https://en.wikipedia.org/wiki/Atbash)
9+
So you would substitute `a` in your input text with `Z` in your output text,
10+
`b` with `Y`, `c` with `X` and so forth.
11+
12+
A few English words also _Atbash_ into other English words:
13+
14+
* irk = rip
15+
* low = old
16+
* hob = sly
17+
* hold = slow
18+
* holy = slob
19+
* horn = slim
20+
* glow = told
21+
* grog = tilt
22+
* zoo = all
23+
24+
Some other English words _Atbash_ into their own reverses, e.g. _wizard_ becomes
25+
_draziw_.
26+
27+
[Atbash]: https://en.wikipedia.org/wiki/Atbash
1228

1329

problems/atbash/atbash.cs

-33
This file was deleted.

problems/atbash/atbash.go

-31
This file was deleted.

problems/atbash/atbash.js

-20
This file was deleted.

problems/atbash/atbash.kt

-13
This file was deleted.

problems/atbash/atbash.php

-18
This file was deleted.

problems/atbash/atbash.py

-36
This file was deleted.

problems/atbash/atbash.rs

-12
This file was deleted.

problems/atbash/atbash.ts

-25
This file was deleted.

problems/atbash/data/001.in

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
abcdefghijklmnopqrstuvwxyz
2+
irk
3+
low
4+
hob
5+
hold
6+
holy
7+
horn
8+
glow
9+
grog
10+
zoo
11+
wizard

problems/atbash/data/001.out

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
zyxwvutsrqponmlkjihgfedcba
2+
rip
3+
old
4+
sly
5+
slow
6+
slob
7+
slim
8+
told
9+
tilt
10+
all
11+
draziw

problems/atbash/solution.bash

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
declare -i a z
5+
a=$(printf %d \'a)
6+
z=$(printf %d \'z)
7+
for ((i = 0; i < ${#1}; i++)); do
8+
if [[ "${1:$i:1}" == $'\n' ]]; then
9+
echo
10+
else
11+
# shellcheck disable=SC2059
12+
printf "\x$(printf %x $((z - ($(printf %d "'${1:$i:1}") - a))))"
13+
fi
14+
done

problems/atbash/solution.c

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
3+
int main(__attribute__ ((unused)) const int argc, const char* argv[]) {
4+
for (int i = 0; argv[1][i] != '\0'; i++) {
5+
printf("%c", argv[1][i] == '\n' ? '\n' : 'z' - (argv[1][i] - 'a'));
6+
}
7+
}

problems/atbash/solution.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
int main(int, const char* argv[]) {
5+
std::string s = argv[1];
6+
for (auto c: s) {
7+
std::cout << (c == '\n' ? c : (char) ('z' - (c - 'a')));
8+
}
9+
}

problems/atbash/solution.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace Atbash {
4+
class Program {
5+
static void Main(string[] args) {
6+
const int z = (int) 'z';
7+
const int a = (int) 'a';
8+
string s = args[0];
9+
foreach (char c in s) {
10+
Console.Write(c == '\n' ? c : (char) (z - (((int)c) - a)));
11+
}
12+
}
13+
}
14+
}

problems/atbash/solution.dart

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env dart
2+
3+
import 'dart:io';
4+
5+
void main(List<String> arguments) {
6+
int a = 'a'.codeUnitAt(0);
7+
int z = 'z'.codeUnitAt(0);
8+
int lf = '\n'.codeUnitAt(0);
9+
arguments[0].runes.forEach((int c) {
10+
stdout.write(String.fromCharCode(c == lf ? c : z - (c - a)));
11+
});
12+
}

problems/atbash/solution.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func main() {
9+
for _, c := range os.Args[1] {
10+
if c == '\n' {
11+
fmt.Println()
12+
} else {
13+
fmt.Printf("%c", 'z'-(c-'a'))
14+
}
15+
}
16+
}

problems/atbash/solution.java

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class solution {
2+
public static void main(String[] args) {
3+
for (char c : args[0].toCharArray()) {
4+
System.out.print(c == '\n' ? c : (char) ('z' - (c - 'a')));
5+
}
6+
}
7+
}

problems/atbash/solution.jl

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env julia
2+
3+
for c in ARGS[1] print(c == '\n' ? c : 'z' - (c - 'a')) end

problems/atbash/solution.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env node
2+
3+
const z = 'z'.charCodeAt(0);
4+
const a = 'a'.charCodeAt(0);
5+
const s = process.argv[2];
6+
for (let i = 0; i < s.length; ++i) {
7+
process.stdout.write(s[i] === '\n' ? '\n' : String.fromCharCode(z - (s.charCodeAt(i) - a)));
8+
}

problems/atbash/solution.kts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env kscript
2+
3+
args[0].forEach { print(if (it == '\n') it else 'z' - (it - 'a')) }

problems/atbash/solution.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
$z = ord('z');
5+
$a = ord('a');
6+
$s = $argv[1];
7+
$l = strlen($argv[1]);
8+
for ($i = 0; $i < $l; ++$i) {
9+
echo $s[$i] === "\n" ? "\n" : chr($z - (ord($s[$i]) - $a));
10+
}

problems/atbash/solution.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
5+
z = ord('z')
6+
a = ord('a')
7+
for c in sys.argv[1]:
8+
print('\n' if c == '\n' else chr(z - (ord(c) - a)), end="")

problems/atbash/solution.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env ruby
2+
3+
a='a'.ord
4+
z='z'.ord
5+
ARGV[0].each_char do |c|
6+
print(c === "\n" ? c : (z - (c.ord - a)).chr)
7+
end

0 commit comments

Comments
 (0)