Debian Codegraph @

crypto-quote.sh

raw symbols SCIP
1 #!/bin/bash
2 # crypto-quote.sh: Encrypt quotes
3
4 # Will encrypt famous quotes in a simple monoalphabetic substitution.
5 # The result is similar to the "Crypto Quote" puzzles
6 #+ seen in the Op Ed pages of the Sunday paper.
7
8
9 key=ETAOINSHRDLUBCFGJMQPVWZYXK
10 # The "key" is nothing more than a scrambled alphabet.
11 # Changing the "key" changes the encryption.
12
13 # The 'cat "$@"' construction gets input either from stdin or from files.
14 # If using stdin, terminate input with a Control-D.
15 # Otherwise, specify filename as command-line parameter.
16
17 cat "$@" | tr "a-z" "A-Z" | tr "A-Z" "$key"
18 # | to uppercase | encrypt
19 # Will work on lowercase, uppercase, or mixed-case quotes.
20 # Passes non-alphabetic characters through unchanged.
21
22
23 # Try this script with something like:
24 # "Nothing so needs reforming as other people's habits."
25 # --Mark Twain
26 #
27 # Output is:
28 # "CFPHRCS QF CIIOQ MINFMBRCS EQ FPHIM GIFGUI'Q HETRPQ."
29 # --BEML PZERC
30
31 # To reverse the encryption:
32 # cat "$@" | tr "$key" "A-Z"
33
34
35 # This simple-minded cipher can be broken by an average 12-year old
36 #+ using only pencil and paper.
37
38 exit 0
39
40 # Exercise:
41 # --------
42 # Modify the script so that it will either encrypt or decrypt,
43 #+ depending on command-line argument(s).