Encryption and Decryption

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • padmanabhanp
    New Member
    • Nov 2006
    • 14

    #1

    Encryption and Decryption

    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.prin tln(c1);
    }
    }
    }

    Thanks in Advance
  • snixten
    New Member
    • Nov 2006
    • 4

    #2
    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.prin tln(name);

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

    System.out.prin tln();

    }
    }

    Comment

    Working...