diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2014-01-20 23:29:11 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2014-01-20 23:29:11 +1300 |
commit | abbe79284a3c78125fc655329a0656428dcb2920 (patch) | |
tree | 55f4f0eebe5bca698fcd4541e01b544a14dca832 /src/org/traccar/helper/Crc.java | |
parent | a7dc44e7b2ebfd8ad70f274ce25727cc9d06118b (diff) | |
download | traccar-server-abbe79284a3c78125fc655329a0656428dcb2920.tar.gz traccar-server-abbe79284a3c78125fc655329a0656428dcb2920.tar.bz2 traccar-server-abbe79284a3c78125fc655329a0656428dcb2920.zip |
Extend meiligao id to IMEI
Diffstat (limited to 'src/org/traccar/helper/Crc.java')
-rw-r--r-- | src/org/traccar/helper/Crc.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/org/traccar/helper/Crc.java b/src/org/traccar/helper/Crc.java index 5a668f30a..213d1192a 100644 --- a/src/org/traccar/helper/Crc.java +++ b/src/org/traccar/helper/Crc.java @@ -154,4 +154,21 @@ public class Crc { return String.format("*%02x", checksum).toUpperCase(); } + public static String luhnChecksum(String s) { + int sum = 0; + boolean evenPosition = true; + for (int i = s.length() - 1; i >= 0; i--) { + int n = Integer.parseInt(s.substring(i, i + 1)); + if (evenPosition) { + n *= 2; + if (n > 9) { + n = (n % 10) + 1; + } + } + sum += n; + evenPosition = !evenPosition; + } + return String.valueOf(10 - sum % 10); + } + } |