diff --git a/ATMegaCard/eeprom_gen.rb b/ATMegaCard/eeprom_gen.rb
index aa0e0db1a64f34306de28f071982ce4b20efd91b..2277921c7de92cad3ed9a8228944b08a8fab0b2d 100755
--- a/ATMegaCard/eeprom_gen.rb
+++ b/ATMegaCard/eeprom_gen.rb
@@ -46,12 +46,20 @@ class IntelHexWriter
 end
 
 def hex2bin(hex)
-	c = hex.length / 2
-	bin = ('.'.encode('ASCII-8BIT'))*c
-	(0...c).each{|i|
-		bin.setbyte(i,hex[i << 1, 2].hex)
-	}
-	return bin
+        c = hex.length / 2
+        bin = ""
+        if ("".respond_to?(:encode))
+                bin = ('.'.encode('ASCII-8BIT'))*c
+                (0...c).each{|i|
+                        bin.setbyte(i,hex[i << 1, 2].hex)
+                }
+        else
+                bin = '.'*c
+                (0...c).each{|i|
+                        bin[i] = hex[i << 1, 2].hex
+                }
+        end
+        return bin
 end
 
 eeprom_file = ARGV[0]
@@ -71,4 +79,4 @@ f.write_data(hex2bin(keystring))
 f.write_data("\xFF"*KEY_LENGTH)
 f.close
 
-puts("OK")
\ No newline at end of file
+puts("OK")