Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. package sit;
  2.  
  3. import java.security.MessageDigest;
  4. import java.security.NoSuchAlgorithmException;
  5.  
  6. public class CarHack {
  7.    
  8.     public static String calculateSalt(String ownid, String id, String n, String hashToFind) throws NoSuchAlgorithmException {
  9.        
  10.         MessageDigest md = MessageDigest.getInstance("SHA-256");
  11.         String firstPart = ownid + id + n;
  12.  
  13.         for (int i = 1; i < 10000000; i++) {
  14.             String toCheck = firstPart.concat(String.valueOf(i));
  15.  
  16.             md.update(toCheck.getBytes());
  17.             byte byteData[] = md.digest();
  18.  
  19.             StringBuffer sb = new StringBuffer();
  20.             for (int j = 0; j < byteData.length; j++) {
  21.                 sb.append(Integer.toString((byteData[j] & 0xff) + 0x100, 16).substring(1));
  22.             }
  23.  
  24.             if (sb.toString().equals(hashToFind)) {
  25.                 System.out.println("Salt = " + i);
  26.                 return sb.toString();
  27.             }
  28.  
  29.             if (i % 1000 == 0) {
  30.                 System.out.println(i);
  31.             }
  32.  
  33.         }
  34.  
  35.         throw new RuntimeException("Salt not found");
  36.     }
  37.  
  38.  
  39.     private static void calculateNewHash(String ownid, String id, String n, String salt) throws NoSuchAlgorithmException {
  40.        
  41.         MessageDigest md = MessageDigest.getInstance("SHA-256");
  42.         String rawData = ownid + id + n + salt;
  43.        
  44.         md.update(rawData.getBytes());
  45.         byte byteData[] = md.digest();
  46.        
  47.         StringBuffer sb = new StringBuffer();
  48.         for (int j = 0; j < byteData.length; j++) {
  49.             sb.append(Integer.toString((byteData[j] & 0xff) + 0x100, 16).substring(1));
  50.         }
  51.  
  52.         System.out.println("New Hash: " + sb.toString());
  53.        
  54.     }
  55.    
  56.     public static void main(String[] args) throws NoSuchAlgorithmException {
  57.         //calculateNewHash bekommt die Werte aus der Aufgabenstellung
  58.         //calculateSalt bekommt die Werte aus dem JavaScript Quellcode der Seite
  59.         calculateNewHash("19d64efd69","door", "4887", calculateSalt("40d120326a", "door", "565", "5e4ca2a4d9d3b94994859ac72dbb97b4d73698c5ff2c3d020a4f89f65cb707e7"));
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement