Update test program
authorMichael Schierl <schierlm@gmx.de>
Wed, 6 Jun 2012 21:48:00 +0000 (23:48 +0200)
committerAndreas Schiermeier <andreas@schiermeier.name>
Sun, 25 Oct 2015 13:51:50 +0000 (14:51 +0100)
Update based on https://wiki.ccc-ffm.de/projekte:tangenerator:start

Some of the "older" codes no longer work - either they were wrong
or the algorithm is.

chiptan/code/FlickerCode.java

index 7deb75e..a31a00f 100644 (file)
@@ -19,6 +19,8 @@ public class FlickerCode {
                        if (xorDigit != 0)
                                throw new RuntimeException("XOR digit incorrect: "+ xorDigit);
                        
+                       StringBuilder luhnDigits = new StringBuilder();
+
                        for (int i = 2; i < number.length()-2; i += 2) {
                                if (remaining > 0) {
                                        remaining--;
@@ -30,18 +32,18 @@ public class FlickerCode {
                                                        digits = digits.substring(0, 1);
                                                rawData.append(digits);
                                        }
+                                       luhnDigits.append(digits);
                                } else {
                                        rawData.append(" ");
                                        isAscii = number.charAt(i) == '1';
                                        remaining = Integer.parseInt(number.substring(i+1, i+2), 16);
                                }
                        }
-                       System.out.println(number+" - "+rawData.toString());
-                       String digits = rawData.toString().replaceAll("[^0-9]", "");
+                       System.out.println(number+" - "+rawData.toString()+" - "+luhnDigits.toString());
                        
                        int sum=checkDigit;
-                       for (int i = 0; i < digits.length(); i++) {
-                               int digit = digits.charAt(i) - '0';
+                       for (int i = 0; i < luhnDigits.length(); i++) {
+                               int digit = Integer.parseInt(luhnDigits.substring(i, i+1), 16);
                                if (i % 2 == 1)
                                        digit *= 2;
                                digit = (digit % 10) + (digit / 10);
@@ -53,7 +55,8 @@ public class FlickerCode {
        }
 
        static String[] samples = {
-               "11048710108705379090700F14362C303063", 
+               "0F04871100030333555414312C32331D",
+               /*"11048710108705379090700F14362C303063", 
                "11048711108705379090700F14362C303042", 
                "11048712108705379090700F14362C303021",
                "11048713108705379090700F14362C303000", 
@@ -72,7 +75,7 @@ public class FlickerCode {
                "11048715681405379090706F14362C303015", 
                "11048715681405379090707F14362C303004", 
                "11048715681405379090708F14362C30309B", 
-               "11048715681405379090709F14362C30308A", 
+               "11048715681405379090709F14362C30308A",*/ 
                "06048002695577", 
                "06048002695654", // "06048002695658", 
                "06048002695735", // "06048002695739",