File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

conversion

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
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

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 7 API documentation
Scala Notes - My blog about Scala
 
 
subject: conversion
 
Similar Threads
Need apache2_0_16 binary version
Hexadecimal Numbers
Multiplication and shif operator
Character and Binary in one file
How to display custom message for inputText field of integer type