https://github.com/getlantern/rot13
https://github.com/getlantern/rot13
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/getlantern/rot13
- Owner: getlantern
- License: apache-2.0
- Created: 2016-08-24T19:27:27.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-08-22T17:22:39.000Z (almost 4 years ago)
- Last Synced: 2024-06-19T19:42:32.761Z (almost 2 years ago)
- Language: Go
- Size: 16.6 KB
- Stars: 3
- Watchers: 11
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rot13 encoder/decoder
Rotates a byte value by thirteen characters.
## Caveat
The name of this package is something of a misnomer: it does not implement
the traditional [ROT13][rot13] substitution cipher. In that cipher, the
value "13" takes on special meaning because the cipher is supposed to
operate on a 26-letter alphabet (2x13); because of this, one can encode and
decode using the same algorithm (it is its own inverse). In contrast, this
library operates on a full _byte_, so its "alphabet" is 256 characters
instead of 26, and thus its algorithm is not its own inverse. If you are
looking for a library to perform the ROT13 Caesar cipher, this is not for
you.
## Command-line use
There is a simple command line interface to this library. Clone the repo and
run `go build cmd/rot13.go` to build it.
Running `rot13 -h` will give you usage information:
Usage of ./rot13:
-encode
Encode the input string (default is to decode)
-input string
Input file; use '-' or leave blank to read from stdin
-output string
Output file; use '-' or leave blank to write to stdout
If you do not specify an input file, it will read from `stdin`; with no
output file specified, it will print results to `stdout`. Some examples:
$ echo 'hello, world!' > hello
$ rot13 -encode -input hello
uryy|9-|yq.
$ rot13 -encode -input hello -output hello_encoded
$ cat hello_encoded
uryy|9-|yq.
$ ./rot13 -input hello_encoded
hello, world!
$ echo 'hello, world!' | ./rot13 -encode
uryy|9-|yq.
$ echo 'hello, world!' | ./rot13 -encode | ./rot13
hello, world!
You can also use Go's testing facility to encode and decode. Supply the
input/output file path as env variables and run:
INFILE=~/.lantern/global.yaml \
OUTFILE=~/.lantern/expanded_global.yaml \
go test -v -run TestFunctional
[rot13]: https://en.wikipedia.org/wiki/ROT13