Skip to content

Instantly share code, notes, and snippets.

@danielpcox danielpcox/Toyota.rb
Created Jan 21, 2016

Embed
What would you like to do?
def hex_to_bytes(str)
str.chars.each_slice(2).map {|s| s.join.to_i(16)}
end
def hex_to_bits(str)
str.chars.each_slice(2).flat_map {|s| s.join.to_i(16).to_s(2).rjust(8,"0").split("")}
end
def bytes_to_binary(bytes)
bytes.flat_map {|b| b.to_s(2).rjust(8,"0").split("")}
end
bicycle = "BICYCLE".bytes
lines = [
"BDB6BCA6BCB3B5538938B26CF1503617C9236C0",
"9D855F7C1A2831944BDB9BCAA5D243EB2323D3E",
"37F2A92D8606D324B3CADD892002ACEE38B61F7",
"D236EB5F8552C3DA384B344543EBCA6BCB3BABD"
]
line = lines.join
bytes = hex_to_bytes(line)
xored = []
bytes.each_with_index do |b,i|
xored << (b ^ bicycle[i % bicycle.length])
end
bits = bytes_to_binary(xored)
c = 0
str = ""
bits.each_with_index do |b,i|
if c % 25 == 0
str << "\n"
end
c += 1
str << b
end
str = str.gsub("0", " ").gsub("1", "")
puts str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.