Skip to content

Commit

Permalink
v1.2.1 - Excluded apache library
Browse files Browse the repository at this point in the history
  • Loading branch information
LowLevelSubmarine committed Sep 29, 2019
1 parent 45e191d commit 3329c3f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 26 deletions.
39 changes: 20 additions & 19 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified out/production/classes/com/lowlevelsubmarine/applock/Hex.class
Binary file not shown.
Binary file modified out/production/classes/com/lowlevelsubmarine/applock/Test.class
Binary file not shown.
38 changes: 32 additions & 6 deletions src/main/java/com/lowlevelsubmarine/applock/Hex.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
package com.lowlevelsubmarine.applock;

import com.sun.org.apache.xerces.internal.impl.dv.util.HexBin;

public class Hex {

public static String encode(byte[] decoded) {
return HexBin.encode(decoded).toLowerCase();
private static final char[] HEX_CODE = "0123456789abcdef".toCharArray();

public static String encode(byte[] data) {
StringBuilder r = new StringBuilder(data.length*2);
for ( byte b : data) {
r.append(HEX_CODE[(b >> 4) & 0xF]);
r.append(HEX_CODE[(b & 0xF)]);
}
return r.toString();
}

public static byte[] decode(String s) {
final int len = s.length();
// "111" is not a valid hex encoding.
if( len%2 != 0 ) {
throw new IllegalArgumentException("hexBinary needs to be even-length: " + s);
}
byte[] out = new byte[len/2];
for( int i=0; i<len; i+=2 ) {
int h = hexToBin(s.charAt(i ));
int l = hexToBin(s.charAt(i+1));
if( h==-1 || l==-1 ) {
throw new IllegalArgumentException("contains illegal character for hexBinary: " + s);
}
out[i/2] = (byte)(h*16+l);
}
return out;
}

public static byte[] decode(String encoded) {
return HexBin.decode(encoded);
private static int hexToBin(char ch) {
if('0'<=ch && ch<='9') return ch-'0';
if('A'<=ch && ch<='F') return ch-'A'+10;
if('a'<=ch && ch<='f') return ch-'a'+10;
return -1;
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/lowlevelsubmarine/applock/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class Test {

private static final byte[] key = AppLock.generateKey(-239757427);
private static final byte[] key = AppLock.generateKey(-239757428);

public static void main(String[] args) {
AppLock appLock = new AppLock(key);
Expand Down

0 comments on commit 3329c3f

Please sign in to comment.