Advertisement
Guest User

HabboEncoding

a guest
Jul 24th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. public static byte[] WriteShort(int in)
  2.     /*    */   {
  3.     /*  7 */     byte[] bytes = new byte[2];
  4.     /*  8 */     bytes[0] = (byte)(in >>> 8 & 0xFF);
  5.     /*  9 */     bytes[1] = (byte)(in >>> 0 & 0xFF);
  6.     /* 10 */     return bytes;
  7.     /*    */   }
  8.     /*    */
  9.     /*    */   public static byte[] WriteInt(int in) {
  10.     /* 14 */     byte[] bytes = new byte[4];
  11.     /* 15 */     bytes[0] = (byte)(in >>> 24 & 0xFF);
  12.     /* 16 */     bytes[1] = (byte)(in >>> 16 & 0xFF);
  13.     /* 17 */     bytes[2] = (byte)(in >>> 8 & 0xFF);
  14.     /* 18 */     bytes[3] = (byte)(in >>> 0 & 0xFF);
  15.     /* 19 */     return bytes;
  16.     /*    */   }
  17.     /*    */
  18.     /*    */   public static byte[] ChompBytes(byte[] bzBytes, int Offset, int numBytes)
  19.     /*    */   {
  20.     /* 24 */     int End = Offset + numBytes;
  21.     /* 25 */     if (End > bzBytes.length) {
  22.     /* 26 */       End = bzBytes.length;
  23.     /*    */     }
  24.     /* 28 */     if (numBytes > bzBytes.length)
  25.     /* 29 */       numBytes = bzBytes.length;
  26.     /* 30 */     if (numBytes < 0) {
  27.     /* 31 */       numBytes = 0;
  28.     /*    */     }
  29.     /* 33 */     byte[] bzChunk = new byte[numBytes];
  30.     /* 34 */     for (int x = 0; x < numBytes; x++)
  31.     /*    */     {
  32.     /* 36 */       bzChunk[x] = bzBytes[(Offset++)];
  33.     /*    */     }
  34.     /*    */
  35.     /* 39 */     return bzChunk;
  36.     /*    */   }
  37.     public static Byte[] EncodeInt16(int x)
  38.     {
  39.         return EncodeInt16((short)x);
  40.     }
  41.     public static Byte[] EncodeInt16(short x)
  42.     {
  43.         return new Byte[]{ (byte)(x >>> 8), (byte)x };
  44.     }
  45.     public static Byte[] EncodeInt32(int x)
  46.     {
  47.         return new Byte[]{ (byte)(x >>> 24), (byte)(x >>> 16), (byte)(x >>> 8), (byte)x };
  48.     }  
  49.     public static Byte[] EncodeString(String x)
  50.     {
  51.         Byte[] Output = new Byte[x.length() + 2];
  52.         int k = 0;
  53.         Byte[] EncodeInt16 = EncodeInt16(x.length());
  54.        
  55.         Output[k++] = EncodeInt16[0];
  56.         Output[k++] = EncodeInt16[1];
  57.        
  58.         for(byte c : x.getBytes())
  59.         {
  60.             Output[k++] = c;
  61.         }
  62.        
  63.         return Output;
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement