Created
January 21, 2016 00:10
-
-
Save danielpcox/2dc2484e33d06e9b6261 to your computer and use it in GitHub Desktop.
This file contains 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
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