Computing.Net > Forums > Programming > Java need code: hex to Ascii

Java need code: hex to Ascii

Reply to Message Icon

Original Message
Name: Saatana
Date: October 3, 2002 at 18:30:38 Pacific
Subject: Java need code: hex to Ascii
OS: WinXP
CPU/Ram: AMD
Comment:

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


public class EncryptDecryptTest
{

public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

String input, input1;
int choice;
int convert;
String inputString;

//try{

do{
System.out.println("\n\t Menu");
System.out.println("\t----------");
System.out.println("\t1. Encrypt");
System.out.println("\t2. Decrypt");
System.out.println("\t3. Exit");

System.out.print("\nEnter choice: ");
choice = in.read();


if(choice == '1')
{

System.out.print("Enter msg to encrypt: ");
input = br.readLine();
inputString = input.toString();
System.out.println("\nThe msg is enrypted to: ");

for(int i = input.length() -1; i>= 0; i--)
{


convert = input.charAt(i);
System.out.println(convert);
}
}

else if(choice == '2')
{

System.out.print("\nEnter encrypted msg to decrypt: ");
input1 = br.readLine();




System.out.println("The msg has been decrypted to: ");
//}



}


else if(choice == '3')
{


System.exit(0);

}
}while (choice != 3);

//}
//catch(IOException ioe){}
}


}



Report Offensive Message For Removal

Response Number 1
Name: Saatana
Date: October 3, 2002 at 18:33:59 Pacific
Subject: Java need code: hex to Ascii
Reply: (edit)

It NEEDS TO BE DEC TO ASCII sorry
its in choice == 2


Report Offensive Follow Up For Removal

Response Number 2
Name: SN
Date: October 3, 2002 at 22:51:54 Pacific
Subject: Java need code: hex to Ascii
Reply: (edit)

It's tough to know what you're trying to do here, but it looks like you're "encrypting" a string by replacing characters with their ascii equivalent. So I guess you want to decrypt from the ascii number to the character. Where does hex come in to play? You're encoding them to just regular old integers. If this is the case, the user will have to separate each ascii value with a space, so you know where one begins and ends. Then you can use the stringTokenizer object (look at the documentation on java.sun.com) to read in each ascii number as a string, the Integer.parseInt(string) to get the integer out of it, then (char)i where i is an integer to get it back to the character value. Use a while loop with the stringTokenizer.numTokens() as a sentinel. I didn't write the code all out because I wasn't sure if I understood the problem properly. If this doesn't help, post back. Good luck,
SN


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Java need code: hex to Ascii

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software