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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Java need code: hex to Ascii

Reply to Message Icon

Name: Saatana
Date: October 3, 2002 at 18:30:38 Pacific
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){}
}


}




Sponsored Link
Ads by Google

Response Number 1
Name: Saatana
Date: October 3, 2002 at 18:33:59 Pacific
Reply:

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


0

Response Number 2
Name: SN
Date: October 3, 2002 at 22:51:54 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


discussion board I need your suggestion



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Java need code: hex to Ascii

Hex to ascii program www.computing.net/answers/programming/hex-to-ascii-program/1960.html

Compiling java source code to .exe www.computing.net/answers/programming/compiling-java-source-code-to-exe/10511.html

Binary to ASCII conv. in assembly www.computing.net/answers/programming/binary-to-ascii-conv-in-assembly/12420.html