Skip to content

Instantly share code, notes, and snippets.

@cyhsutw
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyhsutw/bac27be0d199caf7e49e to your computer and use it in GitHub Desktop.
Save cyhsutw/bac27be0d199caf7e49e to your computer and use it in GitHub Desktop.
Service Security HW-01 by Triforce 5
# Authors:
# => Jevon Mckenzie
# => Amon Bazongo
# => Cheng-Yu Hsu
# XorHelper provides an encode method to xor a file with a key
module XorHelper
# XOR encodes/decodes a document with a key
# Parameters:
# doc: string
# key: string
# Returns: string
def self.encode(doc, key)
return doc.chars.each_with_index.map{ |char, index|
# encrypt with the round-robin method!
(char.ord ^ key[index % key.length].ord).chr
}.join
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment