• Post Reply Bookmark Topic Watch Topic
  • New Topic

converting a javascript function to Java  RSS feed

 
zelimir key
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this function written in JavaScript and would like to use it as server side script. I would appreciate the help on writing this function in java (and adding relevant references java.lang...etc) or any other suggestion which will accomplish hiding the script from the client.
Thanks
function Encrypt(theText) {
output = new String;
Temp = new Array();
Temp2 = new Array();
TextSize = theText.length;
for (i = 0; i < TextSize; i++) {
rnd = Math.round(Math.random() * 122) + 68;
Temp[i] = theText.charCodeAt(i) + rnd;
Temp2[i] = rnd;
}
for (i = 0; i < TextSize; i++) {
output += String.fromCharCode(Temp[i], Temp2[i]);
}
return output;
}
[ May 07, 2004: Message edited by: zk kz ]
[ May 07, 2004: Message edited by: zk kz ]
[ May 07, 2004: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"ze key",
We're pleased to have you here with us in the JSP forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks!
bear
Forum Bartender
[ May 07, 2004: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No one's going to write the code for you. Why not post your attempt at it? And we'll be glad to help you with whatever problems you might be having.
 
zelimir key
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried but had problems with array types, and conversion between varibale types long to string, char to string
private String cryptoString(String theText){
String output;
String Temp[] = null;
String Temp2[] = null;
int TextSize;
TextSize = theText.length();

for (int i = 0; i < TextSize; i++){
long rnd = Math.round(Math.random() * 122) + 68;
//here i got the errors because of varibale type incompatibility
//char, long and string
//When tried to rnd.toString(); got the error
//not sure if charCodeAt is equal to charAt()
Temp[i] = theText.charCodeAt(i) + rnd;
//Temp[i] = theText.charAt(i) + rnd;
Temp2[i] = toString(rnd);
}
for (i = 0; i < TextSize; i++) {
output += String.fromCharCode(Temp[i], Temp2[i]);
}
return output;
}
[ May 07, 2004: Message edited by: ze key ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to adjust your display name as indicated in my original post.
At this point it's become clear that this has very little to do with JSP, so I'm going to move it along to the Java in General(intermediate) forum where it may get mrore attention.
Btw, all of your problems can be easily solved if you just take a look through the API documentation for the String class.
P.S. I also adjusted the topic title to better describe the issue
[ May 07, 2004: Message edited by: Bear Bibeault ]
 
zelimir key
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Please be sure to adjust your display name as indicated in my original post.
At this point it's become clear that this has very little to do with JSP, so I'm going to move it along to the Java in General(intermediate) forum where it may get mrore attention.
Btw, all of your problems can be easily solved if you just take a look through the API documentation for the String class.
P.S. I also adjusted the topic title to better describe the issue
[ May 07, 2004: Message edited by: Bear Bibeault ]

Yes I took a look through the API, and could not figure out how to solve the incompability problem. JavaScript var could hold any type of variable...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!