Posted By

TopcatSoftware on 01/09/11


Tagged

cipher


Versions (?)

xorEncode()


 / Published in: Awk
 

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

xor encryption for gawk.

  1. # xorEncode - Topcat Software LLC. 2011
  2. # http://www.topcat.hypermart.net/index.html
  3. # note: xor is specific to GNU (gawk)
  4. # more info about xor at: http://en.wikipedia.org/wiki/XOR_cipher
  5. # usage example:
  6. # foo = xorEncode("we can be heros...", "mypassword")
  7. # bar = xorEncode(foo, "mypassword")
  8. # print foo
  9. # prinr bar
  10.  
  11. function xorEncode(str, pass, x, y, z, j, ord_a, str_a, pass_a, buf) {
  12.  
  13. x = split(str, str_a, "")
  14. y = split(pass, pass_a, "")
  15.  
  16. for (z = 1; z <= 255; z++) {ord_a[sprintf("%c", z)] = z}
  17.  
  18. for (j = z = 1; z <= x; z++) {
  19. buf = buf sprintf("%c", xor(ord_a[str_a[z]], ord_a[pass_a[j]]))
  20. j = (j < y) ? j++ : 1
  21. }
  22.  
  23. return buf
  24.  
  25. }

Report this snippet  

You need to login to post a comment.