Click to See Complete Forum and Search --> : Java? Please identify


jackson
09-29-2003, 12:25 PM
Yes, it's a silly question, but can someone say with reasonable certainty that the following snippet appears to be java code?

-------------------------

int unlockCode = 0;
for (int i=0; i < userID.length(); i++) {
unlockCode = unlockCode + (byte)userID.charAt(i);
}
result = Integer.toString(unlockCode & 0xFFFF);

-------------------------

AdamBrill
09-29-2003, 12:53 PM
Yes, it does appear to be Java code.... What exactly are you doing with that code?? I'm hoping it doesn't have anything to do with passwords or encryption...

havik
09-29-2003, 02:10 PM
I'd agree, as you would implement that code snippet differently in most other programming languages.

Havik

jackson
09-29-2003, 02:16 PM
HeHe...

Well, actually, it is generic code for a password generator. Here's the deal, a little more clearly:

PalmGear.com is a website which, among other things, operates as a distribution site for Palm and other PDA software. They now offer a "Dynamic Registration" option where the developer uploads a java code snippet to be used to generate registration codes which are compatible the the devloper's application. A user can download apps from PalmGear.com, pay for them using PalmGear's webstore, and get a registration code immediately.

The code I posted was a demo snippet from PalmGear's site.

What I am really looking for is to convert the following pseudoBasic code into a java code snippet. Any chance you could help me with this?

---------------------------------

Dim UserName as String
Dim tempChr as String
Dim i as Integer
Dim tempChr as String
Dim codeString as String
Dim code as Integer

'Make sure username is at least four characters
Do While len(UserName) < 4
UserName=UserName+UserName
Loop

'Get the 4 leftmost characters
UserName=Left(UserName,4)

'Stuff some custom characters into the string
Username=mid(UserName,1,1) + "a" +mid(UserName,2,1)+ "b" + mid(UserName,3,1) + "c" + mid(UserName,4,1)

'read the characters backwards and convert to a string
'of concatenated ascii values
For i=7 to 1 step -1
tempChr=mid(UserName,i,1)
codeString = codeString + str(asc(tempChr))
Next


'multiply the value of the resulting string by some number
'and convert the result beack to a string
Code = val(codeString) * 3
codeString = str(code)

---------------------------------

Using the above example, "Jack" should return a code string of 323999996939322

jackson
09-29-2003, 04:55 PM
(bump)

AdamBrill
09-29-2003, 05:11 PM
Ok, here is the problem... This is JavaScript Forums, not a Java Forums. ;) About the only thing that is similar is the name. :) So, unless you can get Khalid's attention, you'll probably have to go find a Java forums and post your question on there. I'm sorry I can't help...

havik
09-29-2003, 09:49 PM
I'd offer my help as well but I don't have the time at the moment. It would take more effort than I can give at the moment, maybe if this is unanswered in a few days from now I'd be able to help out.

If this is urgent, check out these forums (http://forums.devshed.com) for "java" help.

Havik

Khalid Ali
09-30-2003, 12:57 AM
Here is my first attempt..let me know if this is what you were looking for


import java.util.List;
import java.util.ArrayList;

public class EncryptName {
public EncryptName() {
}

public EncryptName(String[] args) {
char[] custChars = {'a','b','c','d'};
for(int n=0;n<args.length;n++){
//validate each entry from array
char[] arr = validateName(args[n]);//makes sure name is>=4 chars and
//return the first 4 chars
if(arr!=null){
arr = formatName(arr,custChars);
char[] tarr=new char[arr.length];
for(int x=arr.length-1;x>=0;x--){
tarr[((arr.length-1)-x)] = arr[x];
}
String codeStr = "",userName="";

for(int x=0;x<tarr.length;x++){
codeStr += tarr[x] * 3;
userName+= tarr[x];
}
System.out.println("userName ["+userName+"]"+
"\nCoded string ["+codeStr+"]");
}else{
System.out.println("Either name is less then 4 characters or wrong format");
}
}
}

private char[] validateName(String name){
char[] arr=new char[4];
if(name.length()>=4){
for(int n=0;n<name.length();n++){
if(n<4){
arr[n] = name.charAt(n);
}
}
}
return arr;
}

private char[] formatName(char[] arr,char[] custChars){
char[] narr = new char[7];
int n1=0,n2=0,n=0;
while(n<narr.length){
narr[n++] = arr[n1++];
if(n<narr.length-1){
narr[n++] = custChars[n2++];
}
}
return narr;
}

public static void main(String[] args) {
if(args!=null & args.length>0){
EncryptName encryptName1 = new EncryptName(args);
}else{
System.out.println("HELP : please follow the pattern below to run this program\n\n"+
"EncryptName <parameter>\nWhere you can enter multiple paramters\n"+
"A paramter should be in the alphanumeric string");
}
}
}

jackson
09-30-2003, 05:22 AM
Thanks *very much* for the help, Khalid.

It's going to take a few days to digest this but it looks good so far.

Khalid Ali
09-30-2003, 08:54 AM
glad to be of help...:D