package com.philisense.www.utils;

import java.io.*;
import java.util.*;
import com.philisense.www.license.Resources;


public final class ObfuscatedString
{
    private static final String UTF8;
    private final long[] obfuscated;
       
    public static String obfuscate(final String s) {
        if (-1 != s.indexOf(0)) {
            throw new IllegalArgumentException(new ObfuscatedString(new long[] { 2598583114197433456L, -2532951909540716745L, 1850312903926917213L, -7324743161950196342L, 3319654553699491298L }).toString());
        }
        byte[] bytes;
        try {
            bytes = s.getBytes(ObfuscatedString.UTF8);
        }
        catch (UnsupportedEncodingException ex) {
            throw new AssertionError((Object)ex);
        }
        final Random random = new Random();
        final long nextLong = random.nextLong();
        random.setSeed(nextLong);
        final StringBuffer sb = new StringBuffer(new ObfuscatedString(new long[] { -6733388613909857970L, -557652741307719956L, 563088487624542180L, 5623833171491374716L, -2309350771052518321L, 2627844803624578169L }).toString());
        appendHexLiteral(sb, nextLong);
        for (int length = bytes.length, i = 0; i < length; i += 8) {
            final long n = toLong(bytes, i) ^ random.nextLong();
            sb.append(", ");
            appendHexLiteral(sb, n);
        }
        sb.append(new ObfuscatedString(new long[] { 4756003162039514438L, -7241174029104351587L, 2576762727660584163L, 2432800632635846553L }).toString());
        sb.append(s.replaceAll("\\\\", new ObfuscatedString(new long[] { 7866777055383403009L, -5101749501440392498L }).toString()).replaceAll("\"", new ObfuscatedString(new long[] { -8797265930671803829L, -5738757606858957305L }).toString()));
        sb.append(new ObfuscatedString(new long[] { -4228881123273879289L, 1823585417647083411L }).toString());
        return sb.toString();
    }
    
    private static void appendHexLiteral(final StringBuffer sb, final long n) {
        sb.append('0');
        sb.append('x');
        sb.append(Long.toHexString(n).toUpperCase());
        sb.append('L');
    }
    
    private static long toLong(final byte[] array, final int n) {
        final int min = Math.min(array.length, n + 8);
        long n2 = 0L;
        int n3 = min;
        while (--n3 >= n) {
            n2 = (n2 << 8 | (long)(array[n3] & 0xFF));
        }
        return n2;
    }
    
    
    private static void toBytes(long n, final byte[] array, final int n2) {
        for (int min = Math.min(array.length, n2 + 8), i = n2; i < min; ++i) {
            array[i] = (byte)n;
            n >>= 8;
        }
    }
    
    public ObfuscatedString(final long[] array) {
        (this.obfuscated = array.clone())[0] = array[0];
    }
    
    public String toString() {
        final int length = this.obfuscated.length;
        final byte[] array = new byte[8 * (length - 1)];
        final Random random = new Random(this.obfuscated[0]);
        
        for (int i = 1; i < length; ++i) {
            toBytes(this.obfuscated[i] ^ random.nextLong(), array, 8 * (i - 1));
        }
        String s;
        try {
            s = new String(array, ObfuscatedString.UTF8);
        }
        catch (UnsupportedEncodingException ex) {
            throw new AssertionError((Object)ex);
        }
        final int index = s.indexOf(0);
        return (-1 == index) ? s : s.substring(0, index);
    }
    
    static {
        UTF8 = new String(new char[] { 'U', 'T', 'F', '8' });
    }
}
