Ajuda entendimento de CODIGO GERADOR/VALIDADOR CHAVES
Bom dia pessoal,
Sou novo em Java e estou tendo dificuldades em entender o código, alguém poderia dar uma ideia da logica deste calculo?
Sou novo em Java e estou tendo dificuldades em entender o código, alguém poderia dar uma ideia da logica deste calculo?
package com.licenses;
import java.util.*;
public class LicenseKey
{
public String getLicenseKey()
{
return licenseKey;
}
public void setLicenseKey(String licenseKey)
{
this.licenseKey = licenseKey;
}
public LicenseKey(LinkedHashMap args)
{
this(args, 4);
}
public LicenseKey(LinkedHashMap args, int sizeColumns)
{
licenseKey = null;
processLicenseKey(args, sizeColumns);
}
private void processLicenseKey(Map args, int sizeColumns)
{
StringBuffer buffer = new StringBuffer();
String keys[] = new String[args.size()];
String values[] = new String[args.size()];
byte licKey[] = new byte[args.size() * sizeColumns];
byte key[] = new byte[sizeColumns];
Iterator listKeys = args.keySet().iterator();
for(int i = 0; listKeys.hasNext(); i++)
{
keys[i] = (String)listKeys.next();
values[i] = (String)args.get(keys[i]);
}
int pos = 0;
for(int posi = 0; pos < licKey.length && posi < keys.length;)
{
key = truncateValues(keys[posi], values[posi], sizeColumns);
posi++;
for(int posx = 0; posx < key.length; posx++)
{
licKey[pos] = key[posx];
pos++;
}
}
for(int x = 0; x < licKey.length; x++)
{
licKey[x] = rangeByte(licKey[x]);
if(x % sizeColumns == 0 && x > 0 && x < licKey.length - 1)
buffer.append('-');
buffer.append((char)licKey[x]);
}
setLicenseKey(buffer.toString());
}
private byte rangeByte(byte bt)
{
if(bt < 0)
bt *= -1;
if(bt > 0 && bt < 57)
bt += 57;
if(bt < 0)
bt *= -1;
if(bt > 57 && bt < 65)
bt += 65;
if(bt < 0)
bt *= -1;
if(bt > 90 && bt < 97)
bt += 7;
if(bt > 122)
bt -= 5;
if(bt == -128)
bt = 122;
return bt;
}
private byte[] truncateValues(String arg1, String arg2, int size)
{
byte result[] = new byte[size];
byte value1[] = zipValues(arg1, size);
byte value2[] = zipValues(arg2, size);
for(int i = 0; i < size; i++)
result[i] = (byte)((i + 1) * (value1[i] * 2 + value2[i] * 3));
return result;
}
private byte[] zipValues(String args, int size)
{
byte result[] = new byte[size];
for(int i = 0; i < size; i++)
result[i] = 48;
int pos = size - 1;
for(int i = 0; i < args.length(); i++)
{
result[pos] += args.getBytes()[i];
if(--pos < 0)
pos = size - 1;
}
return result;
}
public static int INVALID_LICENSE = -1;
public static int VALID_LICENSE = 0;
public static int EXPIRED_LICENSE = 1;
private String licenseKey;
}
Wellinton Alves
Curtidas 0