• Post Reply Bookmark Topic Watch Topic
  • New Topic

"encripting" strings  RSS feed

 
Guadalupe Ortiz
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to make a simple algorithm to "encript" a String. I mena, for example to change every char in the string for the char situated two places later en the alphabet. It sounds very easy, but how can I do it? How can I convert all the string in an integer (or every char in an integer) and do it back after adding a number??
thanks in advance
Gobellot
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since String objects are immutable you must proceed by getting the String contents as a char[] - where each char can be manipulated to your heart's content. See the java.lang.String javadocs for the toCharArray() method. When done - see the String constructor that takes a char[]
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guadalupe, what you are trying to do is called a simple shift transformation cipher. This is also know as a Caeser cipher after Julius Caeser - the first person to use such a cipher that we know of.
There are some excelent websites covering this. Here is a particulary good one:

http://www.math.nmsu.edu/crypto/public_html/Caesar.html
Once you get some code written, come on back and we'll be happy to help you get it running.
Tom Blough
 
Guadalupe Ortiz
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank-yoy very much for your help both. I�ve got it. Now I have one more question. I did it for encripting "Strings". Now what can I do to encript any other java object that may not be a string??
thanks again for your help
Gobellot
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, I wouldn't think so. What would that mean?
You could surely serialize an object to a string and encrypt that, so somebody would have to decrypt it before they could reconstitute it but I don't think that's really what you were after.
Do you have a real goal or are you just exploring your imagination? If you have like a business requirement the gang here can try to come up with something. If you're just thinkin "What if ..." keep it up! What a great way to learn.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any object that is Serializable can be written to a byte[] (NOT char[]) or a byte stream and encrypted for transmission. See the javax.crypto package for examples.
Bill
 
Guadalupe Ortiz
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was looking at that class but I tried to make a simple example and I wasnt able (maybe I�m so silly....) Could you show me please a simple example (specifyin all the import that are necesary)??
Thank-you very much for your help
Gobellot
 
Guadalupe Ortiz
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was looking at that class but I tried to make a simple example and I wasnt able (maybe I�m so silly....) Could you show me please a simple example (specifyin all the import that are necesary)??
Thank-you very much for your help
Gobellot
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!