com.alachisoft.ncache.ncactivate.license.ebase64 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-activate Show documentation
Show all versions of nc-activate Show documentation
internal package of Alachisoft.
/*
* ebase64.java
*
* Created on October 17, 2006, 12:14 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.alachisoft.ncache.ncactivate.license;
import com.alachisoft.ncache.ncactivate.utils.StringRef;
/**
* @author Administrator
*/
public class ebase64 {
/**
* Creates a new instance of ebase64
*/
public static nbase64 _parent = new nbase64();
public ebase64() {
}
public static String encode(StringRef parr, int ncount) // This one is the external interface
{
if (ncount == 0) return null;
if (parr == null) return null;
if (parr.strData.length() == 0) return null;
encrypt(parr, ncount);
return _parent.encode(parr, ncount);
}
public static int decode(StringRef str, StringRef parr) {
if (parr == null) return _parent.decode(str, null);
int i;
i = _parent.decode(str, parr);
if (i != 0) {
decrypt(parr, i);
}
return i;
}
protected static void encrypt(StringRef parr1, int ncount) {
if (ncount == 0) return;
if (parr1 == null) return;
if (parr1.strData.length() == 0) return;
char[] parr2 = parr1.strData.toCharArray();
char ch, ch1, ch2;
for (int i = 0; i < ncount; i++) {
ch = parr1.strData.charAt(i);
ch ^= (((0x33 + i) % 254) + 1);
ch1 = (char) (ch & 0xf);
ch2 = (char) ((ch >> 4) & 0xf);
parr2[i] = (char) ((ch1 << 4) | ch2);
}
parr1.strData = new String(parr2);
}
protected static void decrypt(StringRef parr1, int ncount) {
if (ncount == 0) return;
if (parr1 == null) return;
if (parr1.strData.length() == 0) return;
char[] parr2 = parr1.strData.toCharArray();
char ch, ch1, ch2;
for (int i = 0; i < ncount; i++) {
ch = parr1.strData.charAt(i);
ch1 = (char) (ch & 0xf);
ch2 = (char) ((ch >> 4) & 0xf);
ch = (char) ((ch1 << 4) | ch2);
parr2[i] = (char) (ch ^ (((0x33 + i) % 254) + 1));
}
parr1.strData = new String(parr2);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy