Last active
August 29, 2015 14:17
-
-
Save cyhsutw/bac27be0d199caf7e49e to your computer and use it in GitHub Desktop.
Service Security HW-01 by Triforce 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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