ruby - How to calculate XOR with offset? -


i want xor calculation different offset list in calculation.

example :

key = [0, 1, 0] text = ["0", "1", "0", "1", "0", "1", "0", "1", "1", "1"] 

the xor calculation:

key[0] ^ text[0] ;  key[1] ^ text[1] ;  key[2] ^ text[2] ;  key[0] ^ text[3] ;  key[1] ^ text[4] ;  key[2] ^ text[5] ;  key[0] ^ text[6] ;  key[1] ^ text[7] ;  key[2] ^ text[8] ; key[0] ^ text[9] ; 

how ?

you can use array#cycle method "cycle" key as needed:

text.zip(key.cycle).map{|t,k| t.to_i ^ k} # => [0, 0, 0, 1, 1, 1, 0, 0, 1, 1] 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -