/ Published in: Awk
URL: http://www.topcat.hypermart.net/index.html
rot13 for awk, extended to include digits
Expand |
Embed | Plain Text
function rot13x(str, from, to, x, y, z, letter, char, buf) { # rot13x for awk - Topcat Software LLC. 2010 # http://www.topcat.hypermart.net/index.html # rot13 cipher extended to include digits # # more info about rot13 at: http://en.wikipedia.org/wiki/ROT13 # a modification of the example found at: # http://www.miranda.org/~jkominek/rot13/awk/ # # example: # # foo = rot13x("some string') # bar = rot13x(foo) # print foo # print bar from = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" to = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm5678901234" x = 62 # length from | to y = length(str) for (z = 1; z <= x; z++) { letter[substr(from, z, 1)] = substr(to, z, 1) } for (z = 1; z <= y; z++) { char = substr(str, z, 1) buf = (char in letter) ? buf letter[char] : buf char } return buf }
You need to login to post a comment.
