Bookmark Topic Watch Topic
  • New Topic

conversion

 
vijay umar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Report post to moderator
What is it you want to achieve with your code ?
 
vijay umar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Report post to moderator
its an algorithm called luby transformation codes! it helps in authentication
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't crosspost.

I'm locking this topic - please continue in your other topic.
 
    Bookmark Topic Watch Topic
  • New Topic