Recently i have a college assignment, to create an XOR encryption and decryption apps. I decided to use ruby to finish this assignment.
there is the source code :
class XOREncrypt def initialize(inputfile, password, outputfile) input = File.open(inputfile,"r") pass_array = password.split(//) output = File.new(outputfile,"w") i = 0 while c = input.getc pass_char = pass_array[i] xor = c.chr ^ pass_char output.print(xor.chr) i+=1 if i == (pass_array.size - 1) i = 0 end end input.close output.close end end puts "Filename for Input : " inputfile = gets puts "Insert Password : " password = gets puts "Filename for Output : " outputfile = gets XOREncrypt.new(inputfile.chomp, password.chomp, outputfile.chomp)
* note :
this apps can by used for encypting and decryting too.
this apps tested and created using ruby 1.8.7
* update :
to use it with ruby 1.9 change the line 9 to
xor = c.ord ^ pass_char.ord