Skip to content

Commit

Permalink
Update for AmuseLabs format change
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesai61 committed May 29, 2022
1 parent 631abac commit 1226084
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,41 @@ protected Puzzle parsePuzzle(JsonObject puzjson) {
return puz;
}

static protected String reverseString(String str) {
StringBuffer b = new StringBuffer(str).reverse();
return b.toString();
}

protected String decode_rawc(String rawc) {
if (! rawc.contains(".")) {
LOG.info("AbstractAmuseLabsDownloader decode_rawc return same rawc");
return new String(Base64.decodeBase64(rawc.getBytes()));
}
String rawcParts[] = rawc.split("\\.");
char buffer[] = rawcParts[0].toCharArray();
char key1[] = reverseString(rawcParts[1]).toCharArray();
int key[] = new int[key1.length];
for (int i = 0; i < key.length; i++) {
key[i] = Character.digit(key1[i], 16) + 2;
}

int i = 0;
int sc = 0;
while (i < (buffer.length - 1)) {
int sl = Math.min(key[sc % key.length], buffer.length - i);
for (int j = 0; j < Math.floorDiv(sl, 2); j++) {
char c = buffer[i+j];
buffer[i+j] = buffer[i + sl - j - 1];
buffer[i + sl - j - 1] = c;
}
i += sl;
sc++;
}
String newRawc = new String(buffer);
LOG.info("AbstractAmuseLabsDownloader decode_rawc return newRawc=" + newRawc);
return new String(Base64.decodeBase64(newRawc.getBytes()));
}

protected File download(Date date, String urlSuffix, Map<String, String> headers) {
String pickerSuffix = getPickerTokenSuffix(date, headers);
String dlurl = baseUrl + pickerSuffix + "&id=" + urlSuffix;
Expand All @@ -313,7 +348,8 @@ protected File download(Date date, String urlSuffix, Map<String, String> headers
String rawc = tokens[1];

// String rawc_decoded = new String(Base64.getDecoder().decode(rawc)); // Required JDK 8 or above
String rawc_decoded = new String(Base64.decodeBase64(rawc.getBytes()));
LongStringLOG("AbstractAmuseLabsDownloader download Got rawc: " + rawc);
String rawc_decoded = decode_rawc(rawc);
LongStringLOG("AbstractAmuseLabsDownloader download Got rawc_decoded: " + rawc_decoded);
JsonObject jsonObject = new JsonParser().parse(rawc_decoded).getAsJsonObject();
p = parsePuzzle(jsonObject);
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ allprojects {
url 'https://oss.sonatype.org/content/groups/public'
}
maven {
url "http://dl.bintray.com/jenzz/maven"
url "https://maven.fabric.io/public"
}
}
gradle.projectsEvaluated {
Expand Down

0 comments on commit 1226084

Please sign in to comment.