blob: 700d7500e681259092156484d2937373577eaca0 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*/
package org.eclipse.osbp.utils.constants;
import java.math.BigInteger;
public class Base26Crypt {
public static long convertToKey(String sName) {
// Convert string into Base-26 number A-Z becomes 0-9A-P...
StringBuffer sbuff = new StringBuffer(sName.replaceAll("(\\W)", "").toUpperCase());
for (int i = 0; i < sbuff.length(); ++i) {
char cVal = sbuff.charAt(i);
if (cVal > 'J')
cVal = (char) (cVal - 'K' + 'A'); // K-Z becomes A-P
else
cVal = (char) (cVal - 'A' + '0'); // A-J becomes 0-9
sbuff.setCharAt(i, cVal);
}
// Convert base-26 string into BigInteger...
BigInteger bigInt = new BigInteger(sbuff.toString(), 26);
// Convert BigInteger into long license key...
long lKey = bigInt.longValue();
return (lKey);
}
}