import javax.swing.JOptionPane; import java.text.DecimalFormat; import java.util.ArrayList; import java.io.BufferedReader; import java.io.FileReader; import java.io.File; /** * A class to encrypt and decode Neopets.com flash game scores. * @author unlimitedorb * @since 4/20/2008 */ public class Crypt { private static final String scoreBase = "http://www.neopets.com/high_scores/process_flash_score.phtml"; private String sh; private String sk; private int gameID; private int wait; private int modifiedGameID; private String bin; private int score; private int dailyChallenge; //Setting it isn't implemented yet. (Don't do Daily Challenges!) private int averageFrameRate; //Isn't currently implemented. public Crypt(String sh, String sk, int gameID, int wait, int score) { this.sh = sh; this.sk = sk; this.gameID = gameID; this.wait = wait; this.score = score; this.dailyChallenge = 0; this.bin = sh + sk; } /* * The class isn't meant to be used as a standalone, but this is provided just in case/for testing * purposes. It's true purpose is as a utility to be used in a bot. */ public static void main(String[] args) { Crypt crypt = new Crypt("none", "none", 500, 500); String request = crypt.getScore(); System.out.println(request); } /** * Method to decode a Neopets.com flash game score. Useful for development. * Hungarian notation in the original swf variables is stripped out. * @param encryptedScore The score to be decoded. */ public static String decode(String encryptedScore) { return ""; } public String encode() { String toEncrypt; //Format the parameter r in the style of ActionScript's Math.random() DecimalFormat rFormat = new DecimalFormat("0.000000000000000000"); int modifiedGameID = 300 * gameID; //There might be extra parameters added, but that's game specific. StringBuilder eScore = new StringBuilder(scoreBase + "?cn=" + modifiedGameID + "&gd=" + wait); eScore.append("&r=" + rFormat.format(Math.random())); toEncrypt = "ssnhsh=" + sh + "&ssnky=" + sk + "&gmd=" + gameID + "&scr=" + score + "&frmrt=" + averageFrameRate + "&chllng=" + dailyChallenge + "&gmdrtn=" + wait; String result = eScore.toString(); return result; } /** * Retrieves keys from the text file "keys.txt" * @return An ArrayList of Neopets.com flash game encryption keys. */ public ArrayList getKeys() { File file = new File("keys.txt"); ArrayList keys = new ArrayList(); keys.ensureCapacity(20); try { BufferedReader reader = new BufferedReader(new FileReader(file)); String line; while((line = reader.readLine())!= null) { keys.add(line); } } catch(Exception e) { e.printStackTrace(); } return keys; } /** * @return the score */ public int getScore() { return this.score; } public void setScore(int score) { this.score = score; } }