Hello,i'm new in java.now i'm working with text conversion.i'm done with conversion string to binary but i dont know how to convert the binary back to original string.below is my working code for text to binary.anyone plez help me to solve this.TQ
HTML Code:
import java.util.*;
import java.io.*;
public class textconversion{
public static void main(String[] args) {
//String choice = "y";
//while (choice.equalsIgnoreCase("y")) {
Scanner input = new Scanner(System.in);
System.out.println ("Enter Message: ");
String msg = input.nextLine();
System.out.println ("Enter Key: ");
String key = input.nextLine();
int keylen = key.length();
byte[] bytes2 = msg.getBytes();
StringBuilder binary2 = new StringBuilder();
for (byte b : bytes2) {
int val = b;
for (int i = 0; i < 8; i++) {
binary2.append((val & 128) == 0 ? 0 : 1);
val <<= 1;
}
binary2.append(' ');
}
System.out.println();
System.out.println();
//System.out.println("Your Message"+" <" + msg + "> Successfully Converted Into Binary: ");
System.out.println();
//System.out.println(binary2);
if(keylen <= 25){
byte[] bytes = key.getBytes();
StringBuilder binary = new StringBuilder();
for (byte b : bytes) {
int val = b;
for (int i = 0; i < 8; i++) {
binary.append((val & 128) == 0 ? 0 : 1);
val <<= 1;
}
binary.append(' ');
}
System.out.println();
System.out.println();
System.out.println("Your Key"+" <" + key + "> Successfully Converted Into Binary: ");
System.out.println();
System.out.println(binary);
//}
}
}
}
Bookmarks