#!/usr/bin/awk -f # # Rot13 shell script # # Copyright (c) 2005 Lorance Stinson BEGIN { # Make everything one long string. IFS = "" # Strings used to rot13 text. ROTFROM = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" ROTTO = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" } { # Rot13 each line. print rot13($0) } function rot13 (string) { retstr = "" # The return string. # Loop over character in the string. for (pos = 0; pos < length(string); pos++) { # Grab the currrent chracter from the string. char = substr(string,pos + 1,1) # Get the position of the character in ROTFROM. rotpos = index(ROTFROM,char) # If the character is in ROTFROM rotate it using ROTTO. if (rotpos > 0) retstr = retstr substr(ROTTO,rotpos,1) # Just print the character. else retstr = retstr char } # Return the rotated string. return retstr }