• Post Reply Bookmark Topic Watch Topic
  • New Topic

Encryption  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi I am coding an Encryption and I have been running into a couple of issues. This program works to encrypt some strings, but I having trouble with strings that would have characters such as z. I'm trying to figure out how to get my code to wrap z around to a, and also if the string entered has spaces I want to be able to encrypt the code with the spaces.
 
Marshal
Posts: 56610
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somebody was asking a similar question a week or so ago, and I responded, but couldn't find it by searching. Oh no, here it is. You will find suggestions for going from 'Z' to 'C' if you add 3.
 
Jon Hankssss
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thanks for the reply. I spent some time trying to figure out the wrapping issue and I found this formula  n = (char)((n - 'a') % 26 + 'a'); works. My assignment says I can assume the message only contains lowercase letters. I haven't got to arrays yet, so I couldn't use the reply on the other post. I still can't figure out how to incorporate spaces to the output of my code.
 
Ranch Hand
Posts: 900
7
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have the choice a One Time Pad would be a better solution.  Not too difficult to code just an XOR with a random number, and much stronger encryption. 
 
Bartender
Posts: 1664
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A One time pad is one of the most simplest of all the algorithms and is uncrackable.
However, there is a catch. To truly implement this logic, you need to have a key that is as long as your data itself. This means that if your data has 2000 characters, your password will be 2000 characters long.
Ideally, the key should be a truly random number (This is not as simple as you might think)
Next, the key that's used once should not be reused to encrypt something else. These are the factors that make it practically useless to use a one time pad.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!