File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic


vijay umar
Ranch Hand

Joined: Mar 24, 2009
Posts: 100
i wish to change a word like "hello" into a binary format in which each letter represented in binary form ex: hello is 01101000 01100101 01101100 01101100 01101111

and i want to take each group of this binary code and perform Xor function between each of them and then to print it.can any body help me with this logic?

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
What is it you want to achieve with your code ?

JDBCSupport - An easy to use, light-weight JDBC framework -
vijay umar
Ranch Hand

Joined: Mar 24, 2009
Posts: 100
its an algorithm called luby transformation codes! it helps in authentication
Rob Spoor

Joined: Oct 27, 2005
Posts: 20273

There are a few steps to this:
- convert the String to characters: either use String.toCharArray() or String.charAt(int) and String.length()
- convert each char into a number. Oh wait, char already is numeric! 't' is the same as (char)104.
- perform xor on each number. The operator is ^.

So in pseudo code:
This will only work for characters that need only one byte, i.e. the ASCII characters (0-127). For others c will be need more than 8 bits to represent itself. You can use a bitwise AND to chop off everything after the first 8 bits: I wrote down 127 here to indicate it is the maximum value of an ASCII character / byte. You will also often see 0x7F (hexadecimal) but that's the same.

How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15082

Please don't crosspost.

I'm locking this topic - please continue in your other topic.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: conversion
It's not a secret anymore!