forked from jchambers/id-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created separate int/long versions of all of the major pieces.
- Loading branch information
Showing
31 changed files
with
731 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/com/eatthepath/idobfuscator/BitRotationLongTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.eatthepath.idobfuscator; | ||
|
||
/** | ||
* Transforms long integers by performing a circular bit shift. | ||
* | ||
* @author <a href="https://github.com/jchambers">Jon Chambers</a> | ||
*/ | ||
public class BitRotationLongTransformer implements LongTransformer { | ||
|
||
private final long originalDistance; | ||
private transient final int effectiveDistance; | ||
|
||
/** | ||
* Constructs a new bit rotation transformer that performs a circular rotation of bits by the given distance. | ||
* | ||
* @param distance the number of places by which to rotate integers | ||
*/ | ||
public BitRotationLongTransformer(final int distance) { | ||
this.originalDistance = distance; | ||
|
||
// Normalize the rotation distance to the range of [0, 64). | ||
this.effectiveDistance = (int) ((distance % Long.SIZE) + (distance < 0 ? Long.SIZE : 0)); | ||
} | ||
|
||
int getEffectiveDistance() { | ||
return this.effectiveDistance; | ||
} | ||
|
||
/** | ||
* Transforms the given long integer by rotating its bits to the left by a prescribed distance. | ||
* | ||
* @param l the long integer to transform | ||
* | ||
* @return the rotated long integer | ||
*/ | ||
@Override | ||
public long transformLong(final long l) { | ||
return (l << this.effectiveDistance) | (l >>> (Long.SIZE - this.effectiveDistance)); | ||
} | ||
|
||
/** | ||
* Reverses a bit rotation by shifting its bits to the right by a prescribed distance. | ||
* | ||
* @param l the long integer to un-rotate | ||
* | ||
* @return the original long integer | ||
*/ | ||
@Override | ||
public long reverseTransformLong(final long l) { | ||
return (l >>> this.effectiveDistance) | (l << (Long.SIZE - this.effectiveDistance)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("BitRotationIntegerTransformer [distance=%d]", this.originalDistance); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.