Skip to content

Instantly share code, notes, and snippets.

@atucom
Created May 1, 2015 18:00
Show Gist options
  • Save atucom/5b52b89ce135fb75fe5f to your computer and use it in GitHub Desktop.
Save atucom/5b52b89ce135fb75fe5f to your computer and use it in GitHub Desktop.
Create hex for proxmark3 and generate 26bit wiegand formatted badge data
#!/usr/bin/env ruby
#the wiegand data format is just 26 bits,
# even_parity_bit + 8bit_facility_code + 16bit_badge_code + odd_parity_bit
# The proxcard II format expects the 26bit part appended to the "magic"
#magic is really the OEM, plus card type, which i've locked to the magic var
# below for my purposes. Change it to match yoursjuu
def generate_44bit_hex(bin)
chopped = bin.chars.each_slice(4).map(&:join)
hex_string = ""
chopped.each do |binary|
hex_string << binary.to_i(2).to_s(base=16)
end
return hex_string
end
def generate_bin(site_code,badge_number) #without parity calculations
badge_bin = "%016b" % badge_number
site_bin = "%08b" % site_code
return site_bin + badge_bin
end
def first_parity(binary_number)
num = binary_number[0..11]
if num.count("1").even?
return '0'
else
return '1'
end
end
def last_parity(binary_number)
num = binary_number[12..24]
if num.count("1").odd?
return '0'
else
return '1'
end
end
def generate_26bit_bin(site_code, badge_number)
non_parity_bin = generate_bin(site_code, badge_number)
start_parity = first_parity(non_parity_bin)
end_parity = last_parity(non_parity_bin)
return (start_parity + non_parity_bin + end_parity)
end
#0.upto(255).each do |site_code|
bin = generate_26bit_bin(110,19657) #test site code + badge number
magic = '00100000000001' #needed to work for 44bit proxcard II format
puts generate_44bit_hex(magic+bin)
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment