By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,737 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,737 IT Pros & Developers. It's quick & easy.

Encryption and Decryption

P: 14
Hai,
I am facing one problem in Encryption(Java). I want to get a string from the user and split that string into characters. After splitting that string into characters, i am changing that character into integer and adding some value to it. what my problem is after adding that value i want change that into String and Store that String in the database.

The Code is

import java.io.*;
import java.lang.*;

class encrypt
{

public static void main (String args[])
{

String name="welcome";
char ch[]=new char[20];
int j;
char c1;
for(int i=0; i<=name.length()-1; i++)
{
ch[i]=name.charAt(i);
j=ch[i]+5;
c1=(char)j;
System.out.println(c1);
}
}
}

Thanks in Advance
Nov 23 '06 #1
Share this Question
Share on Google+
1 Reply


P: 4
Here is the answer you are looking for:

import java.io.*;

public class encrypt
{
public static void main(String args[])
{
String name = "abcd";
char[] chars = new char[20];
int newChar;

System.out.println(name);

for (int i = 0 ; i < name.length() ; i++)
{
chars[i] = name.charAt(i);
newChar = (int) chars[i] + 5;
System.out.print((char) newChar);
}

System.out.println();

}
}
Nov 23 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.