aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/cgCache.java4
-rw-r--r--main/src/cgeo/geocaching/utils/CryptUtils.java27
-rw-r--r--tests/src/cgeo/geocaching/utils/CryptUtilsTest.java8
3 files changed, 7 insertions, 32 deletions
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index 0197248..72e12a5 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -5,6 +5,7 @@ import cgeo.geocaching.activity.IAbstractActivity;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.GCConnector;
import cgeo.geocaching.connector.IConnector;
+import cgeo.geocaching.connector.gc.GCBase;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag;
@@ -14,7 +15,6 @@ import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.geopoint.GeopointParser;
import cgeo.geocaching.utils.CancellableHandler;
-import cgeo.geocaching.utils.CryptUtils;
import cgeo.geocaching.utils.LogTemplateProvider;
import org.apache.commons.collections.CollectionUtils;
@@ -577,7 +577,7 @@ public class cgCache implements ICache {
@Override
public String getCacheId() {
if (StringUtils.isBlank(cacheId) && getConnector().equals(GCConnector.getInstance())) {
- return CryptUtils.convertToGcBase31(geocode);
+ return String.valueOf(GCBase.gccodeToGCId(geocode));
}
return cacheId;
diff --git a/main/src/cgeo/geocaching/utils/CryptUtils.java b/main/src/cgeo/geocaching/utils/CryptUtils.java
index 08703d3..345af88 100644
--- a/main/src/cgeo/geocaching/utils/CryptUtils.java
+++ b/main/src/cgeo/geocaching/utils/CryptUtils.java
@@ -111,31 +111,4 @@ public final class CryptUtils {
return buffer;
}
- public static String convertToGcBase31(final String gccode) {
- final String alphabet = "0123456789ABCDEFGHJKMNPQRTVWXYZ";
-
- if (null == gccode) {
- return "";
- }
-
- char[] characters = gccode.toUpperCase().toCharArray();
-
- if (characters.length <= 2) {
- return "";
- }
-
- final int base = (characters.length <= 5 || (characters.length == 6 && alphabet.indexOf(characters[2]) < 16)) ? 16 : 31;
- int result = 0;
-
- for (int i = 2; i < characters.length; i++) {
- result *= base;
- result += alphabet.indexOf(characters[i]);
- }
-
- if (31 == base) {
- result += Math.pow(16, 4) - 16 * Math.pow(31, 3);
- }
-
- return Integer.toString(result);
- }
}
diff --git a/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java b/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
index 29c0e92..e42df3f 100644
--- a/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.utils;
+import cgeo.geocaching.connector.gc.GCBase;
+
import junit.framework.TestCase;
public class CryptUtilsTest extends TestCase {
@@ -11,8 +13,8 @@ public class CryptUtilsTest extends TestCase {
}
public static void testConvertToGcBase31() {
- assertEquals("1186660", CryptUtils.convertToGcBase31("GC1PKK9"));
- assertEquals("4660", CryptUtils.convertToGcBase31("GC1234"));
- assertEquals("61731", CryptUtils.convertToGcBase31("GCF123"));
+ assertEquals(1186660, GCBase.gccodeToGCId("GC1PKK9"));
+ assertEquals(4660, GCBase.gccodeToGCId("GC1234"));
+ assertEquals(61731, GCBase.gccodeToGCId("GCF123"));
}
}