Posted By

TopcatSoftware on 01/09/11


Tagged

cipher


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

symsec


rot13x()


 / Published in: Awk
 

URL: http://www.topcat.hypermart.net/index.html

rot13 for awk, extended to include digits

  1. function rot13x(str, from, to, x, y, z, letter, char, buf) {
  2.  
  3. # rot13x for awk - Topcat Software LLC. 2010
  4. # http://www.topcat.hypermart.net/index.html
  5. # rot13 cipher extended to include digits
  6. #
  7. # more info about rot13 at: http://en.wikipedia.org/wiki/ROT13
  8. # a modification of the example found at:
  9. # http://www.miranda.org/~jkominek/rot13/awk/
  10. #
  11. # example:
  12. #
  13. # foo = rot13x("some string')
  14. # bar = rot13x(foo)
  15. # print foo
  16. # print bar
  17.  
  18. from = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  19. to = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm5678901234"
  20. x = 62 # length from | to
  21. y = length(str)
  22.  
  23. for (z = 1; z <= x; z++) {
  24. letter[substr(from, z, 1)] = substr(to, z, 1)
  25. }
  26.  
  27. for (z = 1; z <= y; z++) {
  28. char = substr(str, z, 1)
  29. buf = (char in letter) ? buf letter[char] : buf char
  30. }
  31.  
  32. return buf
  33.  
  34. }

Report this snippet  

You need to login to post a comment.