Random Xor Obfuscator : Random « Development « Android






Random Xor Obfuscator

    
//package se.ramfelt.psnfriends.util;

import java.util.Random;
import java.util.StringTokenizer;

public class RandomXorObfuscator {

  private final long seed;

  public RandomXorObfuscator(long seed) {
    this.seed = seed;
  }

  public String perform(String text) {
    if (text == null) {
      return null;
    }
    Random random = new Random(seed);
    StringBuilder builder = new StringBuilder(text.length());
    char[] chars = text.toCharArray();
    for (int i = 0; i < chars.length; i++) {
      builder.append((int)(chars[i] ^ random.nextInt()));
      builder.append(',');
    }
    return builder.toString();
  }
  
  public String reverse(String text) {
    if (text == null) {
      return null;
    }
    StringTokenizer tokenizer = new StringTokenizer(text, ",");
    StringBuilder builder = new StringBuilder();
    Random random = new Random(seed);
    while (tokenizer.hasMoreTokens()) {
      builder.append((char)(Integer.parseInt(tokenizer.nextToken()) ^ random.nextInt()));
    }
    return builder.toString();
  }
}

   
    
    
    
  








Related examples in the same category

1.Random Alphabet Maker
2.Next random Int
3.returns a random number among { 0 to count-1 }
4.Random Generator
5.Get Random Index