Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

incrementing letters  RSS feed

 
Dan Walin
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's something someone may find useful:

I have a new method that I needed to create, it's called "incrementLetters_atoZ". What it does is increment a string of letters just like it was a counter. For example if you pass it ABC, you get ABD back. If you pass abcz you get abda back, etc.

This method just takes a String, increments it by one letter and returns the results. This is designed to keep the length of the string constant, so if you pass ZZZZ, you'll get AAAA back, not AAAAA (like a number increasing digits as it rolls over).

If you have a need for such a thing here it is:

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reminds me a little of the Enigma Machine (used by the Germans for encryption during WWII), with their alphabetical rotors incrementing on each key press.

The point at which these "tripped" varied depending on the rotors, but the common military models had a peculiar "double-stepping" of the middle rotor. When the middle rotor incremented into position to "trip" the left rotor on the next key press, the middle rotor would increment again along with the left rotor.

For example, when rotor I (in the right position) hit 'R' it would trip the adjacent rotor. And when rotor II (in the middle position) hit 'F' it would trip the adjacent rotor. So an example of the double-stepping is...

ADO
ADP
ADQ
AER : Right trips middle into position to trip left
BFS : Middle trips left and double-steps
BFT
BFU
 
Dan Walin
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting - was that due to a flaw in the design or part of some secret code?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dan Walin:
Interesting - was that due to a flaw in the design or part of some secret code?

It was a consequence of the mechanical design. It could be considered a flaw, because the total number of patterns were reduced by skipping over that position of the middle rotor. But from what I've read, this detail was not significant enough to help break the code.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://en.wikipedia.org/wiki/Enigma_machine
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!