Codigo escrito en Visual.
Código:
Function GetKey(rpk) Const rpkOffset=52:i=28 szPossibleChars="BCDFGHJKMPQRTVWXY2346789" Do dwAccumulator=0 : j=14 Do dwAccumulator=dwAccumulator*256 dwAccumulator=rpk(j+rpkOffset)+dwAccumulator rpk(j+rpkOffset)=(dwAccumulator\24) and 255 dwAccumulator=dwAccumulator Mod 24 j=j-1 Loop While j>=0 i=i-1 : szProductKey=mid(szPossibleChars,dwAccumulator+1,1)&szProductKey if (((29-i) Mod 6)=0) and (i<>-1) then i=i-1 : szProductKey="-"&szProductKey End If Loop While i>=0 GetKey=szProductKey End Function
Mi traduccion en JAVA.
Código:
public static String convertirCalveMSWindows(Object[] rpk) { String clave = "N/A"; if (rpk.length != 0) { int rpkOffset = 52; int i = 28; String szPossibleChars = "BCDFGHJKMPQRTVWXY2346789"; clave = ""; while (i >= 0) { int dwAccumulator = 0; int j = 14; while (j >= 0) { dwAccumulator = dwAccumulator * 256; int val = Integer.parseInt(rpk[j + rpkOffset].toString()); dwAccumulator = val + dwAccumulator; rpk[j + rpkOffset] = (dwAccumulator / 24) + 255; dwAccumulator = dwAccumulator % 24; j = j - 1; } i = i - 1; clave = clave + szPossibleChars.charAt(dwAccumulator); if ((29 - i) % 6 == 0 && i != -1) { i = i - 1; clave += "-"; } } } return clave; }